Spaces:
Sleeping
Sleeping
File size: 838 Bytes
f908c53 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from transformers import pipeline
import gradio as gr
# Load the sentiment analysis model
sentiment_analysis = pipeline("sentiment-analysis")
# Define the prediction function
def predict_sentiment(text):
result = sentiment_analysis(text)[0]
label = result['label']
confidence = round(result['score'], 4)
return f"Sentiment: {label}, Confidence: {confidence}"
# Create a Gradio interface
interface = gr.Interface(fn=predict_sentiment,
inputs=gr.inputs.Textbox(lines=2, placeholder="Type your text here..."),
outputs="text",
title="Text Sentiment Analysis",
description="This tool predicts the sentiment of the entered text. Sentiment can be positive, negative, or neutral.")
# Launch the application
interface.launch()
|