mcp-sentiment / app.py
rahuketu86's picture
Upload folder using huggingface_hub
778c0b7 verified
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
# %% auto 0
__all__ = ['demo', 'analyze_sentiment']
# %% app.ipynb 1
import gradio as gr
from textblob import TextBlob
# %% app.ipynb 3
def analyze_sentiment(text):
"""
Analyze the sentiment of the given text.
Args:
text (str): The text to analyze
Returns:
dict: A dictionary containing polarity, subjectivity, and assessment
"""
blob = TextBlob(text)
sentiment = blob.sentiment
assessments = "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
return {"polarity": round(sentiment.polarity, 2),
"subjectivity": round(sentiment.subjectivity, 2),
"assessments": assessments}
# %% app.ipynb 5
demo = gr.Interface(fn=analyze_sentiment,
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
outputs="json",
title="Text Sentiment Analysis",
description="Analyze the sentiment of text using TextBlob")
demo.launch(mcp_server=True)