Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
# app.py
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
from classifier import classify_toxic_comment
|
4 |
|
5 |
def clear_inputs():
|
@@ -255,8 +258,36 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
|
255 |
semantic_similarity_display, empathy_score_display
|
256 |
)
|
257 |
|
258 |
-
def handle_feedback(feedback, comment):
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
|
261 |
submit_btn.click(
|
262 |
fn=lambda: (
|
@@ -296,7 +327,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
|
296 |
|
297 |
feedback_submit.click(
|
298 |
fn=handle_feedback,
|
299 |
-
inputs=[feedback_input, feedback_comment],
|
300 |
outputs=feedback_output
|
301 |
)
|
302 |
|
|
|
1 |
# app.py
|
2 |
import gradio as gr
|
3 |
+
import csv
|
4 |
+
import os
|
5 |
+
from datetime import datetime
|
6 |
from classifier import classify_toxic_comment
|
7 |
|
8 |
def clear_inputs():
|
|
|
258 |
semantic_similarity_display, empathy_score_display
|
259 |
)
|
260 |
|
261 |
+
def handle_feedback(feedback, additional_comment, comment, prediction, confidence):
|
262 |
+
"""
|
263 |
+
Handle user feedback and store it in a CSV file.
|
264 |
+
"""
|
265 |
+
if not feedback:
|
266 |
+
return "Please select a feedback option before submitting."
|
267 |
+
|
268 |
+
# Define the CSV file path
|
269 |
+
csv_file_path = "/home/user/app/feedback.csv"
|
270 |
+
|
271 |
+
# Check if the CSV file exists; if not, create it with headers
|
272 |
+
file_exists = os.path.isfile(csv_file_path)
|
273 |
+
with open(csv_file_path, mode='a', newline='', encoding='utf-8') as csv_file:
|
274 |
+
fieldnames = ['timestamp', 'comment', 'prediction', 'confidence', 'feedback', 'additional_comment']
|
275 |
+
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
|
276 |
+
|
277 |
+
if not file_exists:
|
278 |
+
writer.writeheader() # Write headers if the file is newly created
|
279 |
+
|
280 |
+
# Write the feedback to the CSV
|
281 |
+
writer.writerow({
|
282 |
+
'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
283 |
+
'comment': comment,
|
284 |
+
'prediction': prediction,
|
285 |
+
'confidence': confidence,
|
286 |
+
'feedback': feedback,
|
287 |
+
'additional_comment': additional_comment if additional_comment else "N/A"
|
288 |
+
})
|
289 |
+
|
290 |
+
return f"Thank you for your feedback: {feedback}\nAdditional comment: {additional_comment if additional_comment else 'None'}\nFeedback has been saved."
|
291 |
|
292 |
submit_btn.click(
|
293 |
fn=lambda: (
|
|
|
327 |
|
328 |
feedback_submit.click(
|
329 |
fn=handle_feedback,
|
330 |
+
inputs=[feedback_input, feedback_comment, comment_input, prediction_output, confidence_output],
|
331 |
outputs=feedback_output
|
332 |
)
|
333 |
|