Spaces:
Sleeping
Sleeping
File size: 1,068 Bytes
93c5a68 96abbc7 93c5a68 96abbc7 93c5a68 96abbc7 | 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 30 31 32 33 34 35 36 37 | import gradio as gr
from textblob import TextBlob
def analyze_sentiment(text):
try:
if not text or not text.strip():
return "Please enter some text to analyze"
blob = TextBlob(text)
polarity = blob.sentiment.polarity
if polarity > 0.1:
return f"✅ Positive sentiment (score: {polarity:.2f})"
elif polarity < -0.1:
return f"❌ Negative sentiment (score: {polarity:.2f})"
else:
return f"😐 Neutral sentiment (score: {polarity:.2f})"
except Exception as e:
return f"Error: {str(e)}"
demo = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(label="text", placeholder="Enter text to analyze..."),
outputs=gr.Textbox(label="output"),
title="Text Sentiment Analysis",
description="Analyze the sentiment of text using TextBlob"
)
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False,
debug=False,
show_error=True
) |