Spaces:
Sleeping
Sleeping
SiddanthEmani commited on
Commit ·
096e17e
0
Parent(s):
Initial commit
Browse files- requirements.txt +2 -0
- server.py +33 -0
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|
| 2 |
+
textblob
|
server.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from textblob import TextBlob
|
| 3 |
+
|
| 4 |
+
def sentiment_analysis(text: str) -> dict:
|
| 5 |
+
"""
|
| 6 |
+
Perform sentiment analysis on the input text.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
text (str): The input text to analyze.
|
| 10 |
+
|
| 11 |
+
Returns:
|
| 12 |
+
dict: A dictionary containing the polarity and subjectivity of the text.
|
| 13 |
+
"""
|
| 14 |
+
blob = TextBlob(text)
|
| 15 |
+
sentiment = blob.sentiment
|
| 16 |
+
|
| 17 |
+
return {
|
| 18 |
+
"polarity": sentiment.polarity,
|
| 19 |
+
"subjectivity": sentiment.subjectivity,
|
| 20 |
+
"assessment": "Positive" if sentiment.polarity > 0 else "Negative" if sentiment.polarity < 0 else "Neutral"
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=sentiment_analysis,
|
| 25 |
+
inputs=gr.Textbox(label="Input Text", placeholder="Type your text here..."),
|
| 26 |
+
outputs=gr.JSON(),
|
| 27 |
+
title="Sentiment Analysis",
|
| 28 |
+
description="Analyze the sentiment of your text using TextBlob.",
|
| 29 |
+
theme="ocean",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
demo.launch(mcp_server=True)
|