Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
# Load the sentiment analysis pipeline | |
sentiment_pipeline = pipeline("sentiment-analysis") | |
# Function to analyze sentiment | |
def sentiment_analysis(message, history): | |
result = sentiment_pipeline(message)[0] | |
label = result["label"] | |
score = result["score"] | |
response = f"Sentiment: {label}, Confidence: {score:.2f}" | |
return response | |
# Function to record feedback | |
feedback_store = [] # A list to store feedback | |
def record_feedback(response, feedback): | |
feedback_store.append({"response": response, "feedback": feedback}) | |
return f"Thank you for your feedback! ({len(feedback_store)} recorded)" | |
# Gradio Interface | |
with gr.Blocks() as demo: | |
chat = gr.ChatInterface(fn=sentiment_analysis, type="messages") | |
# Additional components for feedback | |
with gr.Row(): | |
feedback_input = gr.Textbox(placeholder="Enter your feedback here", label="Feedback") | |
record_button = gr.Button("Submit Feedback") | |
# Feedback submission functionality | |
feedback_status = gr.Textbox(interactive=False, label="Feedback Status") | |
record_button.click( | |
fn=record_feedback, | |
inputs=[chat.output_component, feedback_input], | |
outputs=feedback_status, | |
) | |
demo.launch() | |