Spaces:
Sleeping
Sleeping
Nareen Bellamkonda commited on
Commit ·
ccf2a2a
0
Parent(s):
Initial commit
Browse files- app.py +37 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
from textblob import TextBlob
|
| 4 |
+
|
| 5 |
+
def sentiment_analysis(text: str) -> str:
|
| 6 |
+
"""
|
| 7 |
+
Analyze the sentiment for the given text
|
| 8 |
+
|
| 9 |
+
Args: text (str): The text to analyze
|
| 10 |
+
|
| 11 |
+
Returns:
|
| 12 |
+
str: A Json string containing polarity, subjectivity, and sentiment
|
| 13 |
+
|
| 14 |
+
"""
|
| 15 |
+
blob=TextBlob(text)
|
| 16 |
+
sentiment=blob.sentiment
|
| 17 |
+
|
| 18 |
+
result = {
|
| 19 |
+
"polarity" : round(sentiment.polarity, 2),
|
| 20 |
+
"subjectivity" : round(sentiment.subjectivity, 2),
|
| 21 |
+
"sentiment" : "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity <0 else "neutral"
|
| 22 |
+
}
|
| 23 |
+
return json.dumps(result)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
#Create the Gradio interface
|
| 27 |
+
demo=gr.Interface(
|
| 28 |
+
fn=sentiment_analysis,
|
| 29 |
+
inputs=gr.Textbox(lines=10, placeholder="Enter your text here..."),
|
| 30 |
+
outputs=gr.Textbox(),
|
| 31 |
+
title="Sentiment Analysis",
|
| 32 |
+
description="Anlayzes the sentiment of the text using TextBlob"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
demo.launch(mcp_server=True)
|
| 37 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|
| 2 |
+
textblob
|