Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from textblob import TextBlob
|
| 4 |
+
|
| 5 |
+
def sentiment_analysis(text:str)->str:
|
| 6 |
+
"""
|
| 7 |
+
Analyze the sentiment of the text
|
| 8 |
+
Args:
|
| 9 |
+
text: The text to analyze
|
| 10 |
+
Returns:
|
| 11 |
+
A JSON String containing polarity, subjectivity, and assessment
|
| 12 |
+
"""
|
| 13 |
+
blob = TextBlob(text)
|
| 14 |
+
return json.dumps({
|
| 15 |
+
"polarity": round(blob.sentiment.polarity, 2),
|
| 16 |
+
"subjectivity": round(blob.sentiment.subjectivity, 2),
|
| 17 |
+
"assessment": "positive" if blob.sentiment.polarity >0 else "negative" if blob.sentiment.polarity <0 else "neutral"
|
| 18 |
+
})
|
| 19 |
+
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=sentiment_analysis,
|
| 22 |
+
inputs=gr.Textbox(placeholder="Enter your text to analyze"),
|
| 23 |
+
outputs=gr.Textbox(label="Sentiment Analysis"),
|
| 24 |
+
title="Sentiment Analysis",
|
| 25 |
+
description="Analyze the sentiment of the text"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
demo.launch(mcp_server=True)
|