Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from textblob import TextBlob | |
| def analyze_sentiment(text: str) -> dict: | |
| """ | |
| Analyze the sentiment of a text. | |
| Args: | |
| text (str): The text to analyze. | |
| Returns: | |
| dict: A dictionary containing the sentiment analysis results. | |
| """ | |
| blob: TextBlob = TextBlob(text) | |
| sentiment = blob.sentiment | |
| return { | |
| "polarity": sentiment.polarity, | |
| "subjectivity": sentiment.subjectivity, | |
| "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral", | |
| } | |
| demo: gr.Interface = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter your text here..."), | |
| outputs=gr.JSON(), | |
| title="Sentiment Analysis", | |
| description="Analyze the sentiment of a text.", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(mcp_server=True) |