prajwalstha commited on
Commit
f67e2a2
·
0 Parent(s):

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +64 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import gradio as gr
3
+ from textblob import TextBlob
4
+
5
+
6
+ def sentiment_analysis(text: str) -> str:
7
+ """
8
+ Analyze the sentiment of the given text.
9
+
10
+ Args:
11
+ text (str): The text to analyze
12
+
13
+ Returns:
14
+ str: A JSON string containing polarity, subjectivity, and assessment
15
+ """
16
+ blob = TextBlob(text)
17
+ sentiment = blob.sentiment
18
+
19
+ result = {
20
+ "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
21
+ "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
22
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
23
+ }
24
+
25
+ return json.dumps(result)
26
+
27
+
28
+ # Create the Gradio interface
29
+ demo = gr.Interface(
30
+ fn=sentiment_analysis,
31
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
32
+ outputs=gr.Textbox(), # Changed from gr.JSON() to gr.Textbox()
33
+ title="Text Sentiment Analysis",
34
+ description="Analyze the sentiment of text using TextBlob"
35
+ )
36
+
37
+ # Launch the interface and MCP server
38
+ if __name__ == "__main__":
39
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==24.1.0
2
+ annotated-types==0.7.0
3
+ anyio==4.9.0
4
+ audioop-lts==0.2.1
5
+ certifi==2025.6.15
6
+ charset-normalizer==3.4.2
7
+ click==8.2.1
8
+ fastapi==0.115.14
9
+ ffmpy==0.6.0
10
+ filelock==3.18.0
11
+ fsspec==2025.5.1
12
+ gradio==5.34.2
13
+ gradio_client==1.10.3
14
+ groovy==0.1.2
15
+ h11==0.16.0
16
+ hf-xet==1.1.5
17
+ httpcore==1.0.9
18
+ httpx==0.28.1
19
+ httpx-sse==0.4.1
20
+ huggingface-hub==0.33.1
21
+ idna==3.10
22
+ Jinja2==3.1.6
23
+ joblib==1.5.1
24
+ markdown-it-py==3.0.0
25
+ MarkupSafe==3.0.2
26
+ mcp==1.9.3
27
+ mdurl==0.1.2
28
+ nltk==3.9.1
29
+ numpy==2.3.1
30
+ orjson==3.10.18
31
+ packaging==25.0
32
+ pandas==2.3.0
33
+ pillow==11.2.1
34
+ pydantic==2.11.7
35
+ pydantic-settings==2.10.1
36
+ pydantic_core==2.33.2
37
+ pydub==0.25.1
38
+ Pygments==2.19.2
39
+ python-dateutil==2.9.0.post0
40
+ python-dotenv==1.1.1
41
+ python-multipart==0.0.20
42
+ pytz==2025.2
43
+ PyYAML==6.0.2
44
+ regex==2024.11.6
45
+ requests==2.32.4
46
+ rich==14.0.0
47
+ ruff==0.12.1
48
+ safehttpx==0.1.6
49
+ semantic-version==2.10.0
50
+ shellingham==1.5.4
51
+ six==1.17.0
52
+ sniffio==1.3.1
53
+ sse-starlette==2.3.6
54
+ starlette==0.46.2
55
+ textblob==0.19.0
56
+ tomlkit==0.13.3
57
+ tqdm==4.67.1
58
+ typer==0.16.0
59
+ typing-inspection==0.4.1
60
+ typing_extensions==4.14.0
61
+ tzdata==2025.2
62
+ urllib3==2.5.0
63
+ uvicorn==0.34.3
64
+ websockets==15.0.1