Spaces:
Build error
Build error
File size: 1,001 Bytes
aef62a0 3b593aa 61622ee 3b593aa 61622ee 3b593aa 61622ee 61fe723 aef62a0 effa8a5 | 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 | import gradio as gr
from transformers import pipeline
# Initialize the sentiment-analysis pipeline
classifier = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
def respond(message):
# Get the sentiment analysis result
sentiment_result = classifier(message)
# Process the result to extract the sentiment label and score
sentiment_label = sentiment_result[0]['label']
sentiment_score = sentiment_result[0]['score']
# Generate a response based on the sentiment analysis
response = f"Sentiment: {sentiment_label} (Confidence: {sentiment_score * 100:.2f}%)"
return response
demo = gr.Interface(
fn=respond,
inputs=gr.Textbox(label="Input Text"),
outputs=gr.Textbox(label="Sentiment Analysis Result"),
allow_flagging="never", # Disable flagging (optional, but good for API usage)
)
if __name__ == "__main__":
demo.launch(share=True) # Use share=True to expose the interface publicly
|