Spaces:
Sleeping
Sleeping
File size: 1,055 Bytes
0eb21a1 |
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 |
import gradio as gr
from textblob import TextBlob
def analyze_sentiment(text) -> dict:
"""
Analyze the sentiment of the input text.
Args:
text (str): The input text to analyze.
Returns:
dict: A dictionary containing the polarity, subjectivity, and assessment of the text.
"""
blob = TextBlob(text)
sentiment = blob.sentiment
return {
f"polarity: {round(sentiment.polarity, 2)}",
f"subjectivity: {round(sentiment.subjectivity, 2)}",
f"assessment: {'positive' if sentiment.polarity > 0 else 'negative' if sentiment.polarity < 0 else 'neutral'}"
}
demo = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(label="Input Text", placeholder="Enter text to analyze sentiment..."),
outputs=gr.JSON(),
title="Sentiment Analysis with TextBlob",
description="This app analyzes the sentiment of the input text using TextBlob and returns the polarity, subjectivity, and assessment.",
)
if __name__ == "__main__":
demo.launch(mcp_server=True) |