QOL improvements
Browse files
app.py
CHANGED
@@ -25,6 +25,8 @@ db_connection = mysql.connector.connect(
|
|
25 |
|
26 |
db_cursor = db_connection.cursor()
|
27 |
|
|
|
|
|
28 |
|
29 |
def get_potential_labels():
|
30 |
# get potential labels from db
|
@@ -61,6 +63,12 @@ def classify_email(constituent_email):
|
|
61 |
return ", ".join(top_labels)
|
62 |
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
# Function to handle saving data
|
65 |
def save_data(orig_user_email, constituent_email, labels, user_response, current_user):
|
66 |
# save the data to the database
|
@@ -80,27 +88,41 @@ def save_data(orig_user_email, constituent_email, labels, user_response, current
|
|
80 |
|
81 |
db_cursor = db_connection.cursor()
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
try:
|
84 |
volley = 1
|
85 |
if orig_user_email != "":
|
86 |
db_cursor.execute(
|
87 |
-
"INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (
|
88 |
-
(orig_user_email, volley),
|
89 |
)
|
90 |
volley = 2
|
91 |
|
92 |
db_cursor.execute(
|
93 |
-
"INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (
|
94 |
-
(constituent_email, volley),
|
95 |
)
|
96 |
|
97 |
db_cursor.execute(
|
98 |
-
"INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (
|
99 |
-
(user_response, volley + 1),
|
100 |
)
|
101 |
|
102 |
# insert a row into the message_categorys_associations table for each valid label in labels with the message_id of the constituent_email
|
103 |
-
|
|
|
|
|
|
|
104 |
for label in labels:
|
105 |
label_exists = db_cursor.execute(
|
106 |
"SELECT * FROM radmap_frog12.message_categorys WHERE message_category_name = %s",
|
@@ -176,7 +198,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
176 |
|
177 |
with gr.Column():
|
178 |
classification_output = gr.TextArea(
|
179 |
-
label="Suggested Message Categories (modify as needed)",
|
180 |
lines=1,
|
181 |
interactive=True,
|
182 |
)
|
|
|
25 |
|
26 |
db_cursor = db_connection.cursor()
|
27 |
|
28 |
+
ORG_ID = 731
|
29 |
+
|
30 |
|
31 |
def get_potential_labels():
|
32 |
# get potential labels from db
|
|
|
63 |
return ", ".join(top_labels)
|
64 |
|
65 |
|
66 |
+
def remove_spaces_after_comma(s):
|
67 |
+
parts = s.split(",")
|
68 |
+
parts = [part.strip() for part in parts]
|
69 |
+
return ",".join(parts)
|
70 |
+
|
71 |
+
|
72 |
# Function to handle saving data
|
73 |
def save_data(orig_user_email, constituent_email, labels, user_response, current_user):
|
74 |
# save the data to the database
|
|
|
88 |
|
89 |
db_cursor = db_connection.cursor()
|
90 |
|
91 |
+
if current_user == "Sheryl Springer":
|
92 |
+
person_id = 11021
|
93 |
+
elif current_user == "Diane Taylor":
|
94 |
+
person_id = 11023
|
95 |
+
elif current_user == "Ann E. Belyea":
|
96 |
+
person_id = 11025
|
97 |
+
elif current_user == "Marcelo Mejia":
|
98 |
+
person_id = 11027
|
99 |
+
elif current_user == "Rishi Vasudeva":
|
100 |
+
person_id = 11029
|
101 |
+
|
102 |
try:
|
103 |
volley = 1
|
104 |
if orig_user_email != "":
|
105 |
db_cursor.execute(
|
106 |
+
"INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (345678, %s, %s, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', %s)",
|
107 |
+
(ORG_ID, person_id, orig_user_email, volley),
|
108 |
)
|
109 |
volley = 2
|
110 |
|
111 |
db_cursor.execute(
|
112 |
+
"INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (345678, %s, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', %s)",
|
113 |
+
(ORG_ID, constituent_email, volley),
|
114 |
)
|
115 |
|
116 |
db_cursor.execute(
|
117 |
+
"INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (345678, %s, %s, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', %s)",
|
118 |
+
(ORG_ID, person_id, user_response, volley + 1),
|
119 |
)
|
120 |
|
121 |
# insert a row into the message_categorys_associations table for each valid label in labels with the message_id of the constituent_email
|
122 |
+
# if there is a comma, remove all spaces after the comma
|
123 |
+
|
124 |
+
labels = remove_spaces_after_comma(labels)
|
125 |
+
labels = labels.split(",")
|
126 |
for label in labels:
|
127 |
label_exists = db_cursor.execute(
|
128 |
"SELECT * FROM radmap_frog12.message_categorys WHERE message_category_name = %s",
|
|
|
198 |
|
199 |
with gr.Column():
|
200 |
classification_output = gr.TextArea(
|
201 |
+
label="Suggested Message Categories (modify as needed). Separate categories with commas",
|
202 |
lines=1,
|
203 |
interactive=True,
|
204 |
)
|