Spaces:
Sleeping
Sleeping
File size: 1,183 Bytes
be1c032 |
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 34 35 36 37 38 39 40 41 42 |
import gradio as gr
from textblob import TextBlob
def sentiment_analysis(text: str) -> dict:
"""
Performs sentiment analysis on the input text.
Args:
text (str): The text to analyze.
Returns:
dict: A dictionary containing polarity, subjectivity, and a qualitative assessment.
"""
blob = TextBlob(text)
polarity = blob.sentiment.polarity
subjectivity = blob.sentiment.subjectivity
if polarity > 0.1:
assessment = "positive"
elif polarity < -0.1:
assessment = "negative"
else:
assessment = "neutral"
return {
"polarity": polarity,
"subjectivity": subjectivity,
"assessment": assessment
}
iface = gr.Interface(
fn=sentiment_analysis,
inputs=gr.Textbox(lines=2, placeholder="Enter text for sentiment analysis..."),
outputs=gr.JSON(),
title="Sentiment Analysis Tool (MCP Enabled)",
description="Enter text to get its sentiment polarity, subjectivity, and a qualitative assessment. This server is MCP enabled."
)
if __name__ == "__main__":
# Launch the server with mcp_server=True to enable the MCP endpoint
iface.launch(mcp_server=True)
|