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()