File size: 1,510 Bytes
5c93031
a2304a1
f32907e
 
 
458aedf
5c93031
f32907e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
import os
import csv
import time

token = os.getenv('HF_TOKEN')

def save_feedback(text, original_output, corrected_label):  
    with open('/data/feedback_data.csv', 'a', newline='') as f:
        predicted_label = max(original_output, key=original_output.get)
        writer = csv.writer(f)
        writer.writerow([text, original_output, predicted_label, corrected_label])
    return "Feedback saved successfully!"

def clear_message():
    time.sleep(1)  # Wait for 1 seconds
    return gr.update(value="")

with gr.Blocks() as demo:
    # Load the classification app
    classification_app = gr.load("models/ressolve-ai/sentiment_cobranzas_BAL4", hf_token=token)

    # Get the input and output components from the loaded app
    text_input = classification_app.input_components[0]
    output_label = classification_app.output_components[0]

    # Add a subtitle before the feedback section
    gr.Markdown("## Feedback the sentiment")

    # Add feedback buttons below the classification app
    with gr.Row():
        feedback_label = gr.Radio(["Positivo", "Negativo", "Neutro"], label="Correct Label") 
        feedback_btn = gr.Button("If applicable, press this button to correct the label")
        feedback_message = gr.Textbox(label="Feedback Status", interactive=False)

    feedback_btn.click(save_feedback, inputs=[text_input, output_label, feedback_label], outputs=feedback_message)
    feedback_btn.click(clear_message, inputs=None, outputs=feedback_message)

demo.launch()