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