Spaces:
Sleeping
Sleeping
style upgrades
Browse files
app.py
CHANGED
@@ -62,7 +62,7 @@ def classify_email(constituent_email):
|
|
62 |
|
63 |
|
64 |
# Function to handle saving data
|
65 |
-
def save_data(orig_user_email, constituent_email, labels, user_response):
|
66 |
# save the data to the database
|
67 |
# orig_user_email should have volley 0
|
68 |
# constituent_email should have volley 1
|
@@ -81,19 +81,22 @@ def save_data(orig_user_email, constituent_email, labels, user_response):
|
|
81 |
db_cursor = db_connection.cursor()
|
82 |
|
83 |
try:
|
84 |
-
|
85 |
-
|
86 |
-
(
|
87 |
-
|
|
|
|
|
|
|
88 |
|
89 |
db_cursor.execute(
|
90 |
-
"INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking',
|
91 |
-
(constituent_email,),
|
92 |
)
|
93 |
|
94 |
db_cursor.execute(
|
95 |
-
"INSERT INTO radmap_frog12.messages (app_id, org_id, person_id, communication_method_id, status_id, subject, body, send_date, message_type, volley) VALUES (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking',
|
96 |
-
(user_response,),
|
97 |
)
|
98 |
|
99 |
# insert a row into the message_categorys_associations table for each valid label in labels with the message_id of the constituent_email
|
@@ -118,7 +121,7 @@ def save_data(orig_user_email, constituent_email, labels, user_response):
|
|
118 |
|
119 |
db_connection.commit()
|
120 |
|
121 |
-
return "
|
122 |
|
123 |
except Exception as e:
|
124 |
print(e)
|
@@ -135,34 +138,45 @@ auth = [(auth_username, auth_password)]
|
|
135 |
|
136 |
# Start building the Gradio interface
|
137 |
# Start building the Gradio interface with two columns
|
138 |
-
with gr.Blocks() as app:
|
139 |
with gr.Row():
|
140 |
-
gr.Markdown("##
|
141 |
|
142 |
with gr.Row():
|
143 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
email_labels_input = gr.Markdown(
|
145 |
-
"##
|
146 |
)
|
147 |
|
148 |
original_email_input = gr.TextArea(
|
149 |
placeholder="Enter the original email sent by you",
|
150 |
-
label="Your Original Email",
|
151 |
)
|
152 |
|
153 |
spacer1 = gr.Label(visible=False)
|
154 |
|
155 |
constituent_response_input = gr.TextArea(
|
156 |
-
placeholder="Enter the
|
157 |
-
label="
|
158 |
lines=15,
|
159 |
)
|
160 |
|
161 |
-
classify_button = gr.Button("
|
162 |
|
163 |
with gr.Column():
|
164 |
classification_output = gr.TextArea(
|
165 |
-
label="
|
166 |
lines=1,
|
167 |
interactive=True,
|
168 |
)
|
@@ -171,11 +185,11 @@ with gr.Blocks() as app:
|
|
171 |
|
172 |
user_response_input = gr.TextArea(
|
173 |
placeholder="Enter your response to the constituent",
|
174 |
-
label="
|
175 |
lines=25,
|
176 |
)
|
177 |
|
178 |
-
save_button = gr.Button("Save
|
179 |
save_output = gr.Label(label="Backend Response")
|
180 |
|
181 |
# Define button actions
|
@@ -192,6 +206,7 @@ with gr.Blocks() as app:
|
|
192 |
constituent_response_input,
|
193 |
classification_output,
|
194 |
user_response_input,
|
|
|
195 |
],
|
196 |
outputs=save_output,
|
197 |
)
|
|
|
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
|
67 |
# orig_user_email should have volley 0
|
68 |
# constituent_email should have volley 1
|
|
|
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 (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', 0)",
|
88 |
+
(orig_user_email,),
|
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 (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', %s)",
|
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 (0, 0, 0, 1, 1, 'Email Classification and Response Tracking', %s, NOW(), 'Email Classification and Response Tracking', %s)",
|
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
|
|
|
121 |
|
122 |
db_connection.commit()
|
123 |
|
124 |
+
return "Response successfully saved to database"
|
125 |
|
126 |
except Exception as e:
|
127 |
print(e)
|
|
|
138 |
|
139 |
# Start building the Gradio interface
|
140 |
# Start building the Gradio interface with two columns
|
141 |
+
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
142 |
with gr.Row():
|
143 |
+
gr.Markdown("## Campaign Messaging Assistant")
|
144 |
|
145 |
with gr.Row():
|
146 |
with gr.Column():
|
147 |
+
current_user = gr.Dropdown(
|
148 |
+
label="Current User",
|
149 |
+
choices=[
|
150 |
+
"Sheryl Springer",
|
151 |
+
"Ann E. Belyea",
|
152 |
+
"Marcelo Mejia",
|
153 |
+
"Rishi Vasudeva",
|
154 |
+
"Diane Taylor",
|
155 |
+
],
|
156 |
+
)
|
157 |
+
|
158 |
email_labels_input = gr.Markdown(
|
159 |
+
"## Message Category Library\n ### " + ", ".join(potential_labels),
|
160 |
)
|
161 |
|
162 |
original_email_input = gr.TextArea(
|
163 |
placeholder="Enter the original email sent by you",
|
164 |
+
label="Your Original Email (if any)",
|
165 |
)
|
166 |
|
167 |
spacer1 = gr.Label(visible=False)
|
168 |
|
169 |
constituent_response_input = gr.TextArea(
|
170 |
+
placeholder="Enter the incoming message",
|
171 |
+
label="Incoming Message (may be a response to original email)",
|
172 |
lines=15,
|
173 |
)
|
174 |
|
175 |
+
classify_button = gr.Button("Process Message", variant="primary")
|
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 |
)
|
|
|
185 |
|
186 |
user_response_input = gr.TextArea(
|
187 |
placeholder="Enter your response to the constituent",
|
188 |
+
label="Suggested Response (modify as needed)",
|
189 |
lines=25,
|
190 |
)
|
191 |
|
192 |
+
save_button = gr.Button("Save Response", variant="primary")
|
193 |
save_output = gr.Label(label="Backend Response")
|
194 |
|
195 |
# Define button actions
|
|
|
206 |
constituent_response_input,
|
207 |
classification_output,
|
208 |
user_response_input,
|
209 |
+
current_user,
|
210 |
],
|
211 |
outputs=save_output,
|
212 |
)
|