Spaces:
Sleeping
Sleeping
| 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 | |
| ) |