Vibhoraec commited on
Commit
6c8cb3c
·
verified ·
1 Parent(s): a1b3165

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from textblob import TextBlob
3
+
4
+ def sentiment_analysis(text: str) -> dict:
5
+ """Analyze sentiment and return polarity/subjectivity/assessment."""
6
+ pol = round(TextBlob(text).sentiment.polarity, 2) # [-1, 1]
7
+ subj = round(TextBlob(text).sentiment.subjectivity, 2) # [0, 1]
8
+ return {
9
+ "polarity": pol,
10
+ "subjectivity": subj,
11
+ "assessment": "positive" if pol > 0 else "negative" if pol < 0 else "neutral",
12
+ }
13
+
14
+ demo = gr.Interface(
15
+ fn=sentiment_analysis,
16
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
17
+ outputs=gr.JSON(),
18
+ title="Text Sentiment Analysis",
19
+ description="Analyze the sentiment of text using TextBlob",
20
+ )
21
+
22
+ if __name__ == "__main__":
23
+ demo.launch(mcp_server=True) # enables the MCP server alongside the UI