feedback1
Browse files
app.py
CHANGED
@@ -1,5 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
|
|
|
|
3 |
token = os.getenv('HF_TOKEN')
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import csv
|
4 |
+
import time
|
5 |
+
|
6 |
token = os.getenv('HF_TOKEN')
|
7 |
|
8 |
+
def save_feedback(text, original_output, corrected_label):
|
9 |
+
with open('/data/feedback_data.csv', 'a', newline='') as f:
|
10 |
+
predicted_label = max(original_output, key=original_output.get)
|
11 |
+
writer = csv.writer(f)
|
12 |
+
writer.writerow([text, original_output, predicted_label, corrected_label])
|
13 |
+
return "Feedback saved successfully!"
|
14 |
+
|
15 |
+
def clear_message():
|
16 |
+
time.sleep(1) # Wait for 1 seconds
|
17 |
+
return gr.update(value="")
|
18 |
+
|
19 |
+
with gr.Blocks() as demo:
|
20 |
+
# Load the classification app
|
21 |
+
classification_app = gr.load("models/ressolve-ai/sentiment_cobranzas_BAL4", hf_token=token)
|
22 |
+
|
23 |
+
# Get the input and output components from the loaded app
|
24 |
+
text_input = classification_app.input_components[0]
|
25 |
+
output_label = classification_app.output_components[0]
|
26 |
+
|
27 |
+
# Add a subtitle before the feedback section
|
28 |
+
gr.Markdown("## Feedback the sentiment")
|
29 |
+
|
30 |
+
# Add feedback buttons below the classification app
|
31 |
+
with gr.Row():
|
32 |
+
feedback_label = gr.Radio(["Positivo", "Negativo", "Neutro"], label="Correct Label")
|
33 |
+
feedback_btn = gr.Button("If applicable, press this button to correct the label")
|
34 |
+
feedback_message = gr.Textbox(label="Feedback Status", interactive=False)
|
35 |
+
|
36 |
+
feedback_btn.click(save_feedback, inputs=[text_input, output_label, feedback_label], outputs=feedback_message)
|
37 |
+
feedback_btn.click(clear_message, inputs=None, outputs=feedback_message)
|
38 |
+
|
39 |
+
demo.launch()
|