mcp-sentiment / app.py
ninooo96's picture
fix app.py
71df27e
raw
history blame contribute delete
966 Bytes
import json
import gradio as gr
from transformers import pipeline
def sentiment_analysis(text: str) -> str:
"""
Analyze the sentiment of the given text.
Args:
text (str): The text to analyze
Returns:
str: A JSON string containing polarity, subjectivity, and assessment
"""
sentiment_pipeline = pipeline("sentiment-analysis")
sentiment = sentiment_pipeline(text)[0]
result = {
"SENTIMENT": sentiment['label'],
"SCORE": sentiment['score']
}
return json.dumps(result)
# Create the Gradio interface
demo = gr.Interface(
fn=sentiment_analysis,
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
title="Text Sentiment Analysis",
description="Analyze the sentiment of text using DistilBert model."
)
# Launch the interface and MCP server
if __name__ == "__main__":
demo.launch(mcp_server=True)