Spaces:
Runtime error
Runtime error
File size: 1,283 Bytes
3f52b23 bfdd25e 3f52b23 5085916 5b327e7 5085916 5b327e7 5085916 5b327e7 5085916 |
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 40 |
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()
|