Spaces:
Sleeping
Sleeping
File size: 660 Bytes
78fc150 bcb9497 78fc150 bcb9497 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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()
|