Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| from textblob import TextBlob | |
| # Create a simple function for sentiment analysis | |
| def sentiment_analysis(message, history): | |
| """ | |
| Perform sentiment analysis on the input text and return a formatted result. | |
| """ | |
| blob = TextBlob(message) | |
| sentiment = blob.sentiment | |
| assessment = "Positive" if sentiment.polarity > 0 else "Negative" if sentiment.polarity < 0 else "Neutral" | |
| return f"Sentiment Analysis: {assessment}\nPolarity: {sentiment.polarity:.2f}\nSubjectivity: {sentiment.subjectivity:.2f}" | |
| # Create our demo interface | |
| def create_demo(): | |
| # Create a basic ChatInterface with just sentiment analysis | |
| interface = gr.ChatInterface( | |
| fn=sentiment_analysis, | |
| examples=["I love this application, it's amazing!", | |
| "I'm feeling a bit disappointed with the results.", | |
| "This is just a neutral statement about facts."], | |
| title="Sentiment Analysis Chatbot", | |
| description="Ask me to analyze the sentiment of your text!", | |
| theme="ocean" | |
| ) | |
| return interface | |
| # Create the demo | |
| demo = create_demo() | |
| # No cleanup needed for this simplified version | |
| def cleanup(): | |
| pass |