Spaces:
Sleeping
Sleeping
import gradio as gr | |
from textblob import TextBlob | |
# Define the sentiment analysis function | |
def analyze_sentiment(text): | |
# Create a TextBlob object | |
blob = TextBlob(text) | |
# Extract sentiment | |
polarity = blob.sentiment.polarity | |
subjectivity = blob.sentiment.subjectivity | |
# Determine sentiment type | |
sentiment = "POSITIVE" if polarity >= 0 else "NEGATIVE" | |
# Return formatted string with results | |
return f"Sentiment: {sentiment}\nPolarity: {polarity:.2f}\nSubjectivity: {subjectivity:.2%}" | |
# Create a Gradio interface | |
iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text") | |
# Launch the interface | |
iface.launch() | |