Vladt-Tempest commited on
Commit
881d8d0
·
1 Parent(s): 56bc197

sentiment analysis

Browse files
Files changed (2) hide show
  1. app.py +25 -14
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,23 +1,34 @@
1
  import gradio as gr
 
 
 
 
 
2
 
3
- def letter_counter(word, letter):
4
- """Count the occurrences of a specific letter in a word.
5
-
6
  Args:
7
- word: The word or phrase to analyze
8
- letter: The letter to count occurrences of
9
-
10
  Returns:
11
- The number of times the letter appears in the word
12
  """
13
- return word.lower().count(letter.lower())
 
 
 
 
 
 
 
14
 
 
15
  demo = gr.Interface(
16
- fn=letter_counter,
17
- inputs=["text", "text"],
18
- outputs="number",
19
- title="Letter Counter",
20
- description="Count how many times a letter appears in a word"
21
  )
22
 
23
- demo.launch(mcp_server=True)
 
 
 
1
  import gradio as gr
2
+ from textblob import TextBlob
3
+
4
+ def sentiment_analysis(text: str) -> dict:
5
+ """
6
+ Analyze the sentiment of the given text.
7
 
 
 
 
8
  Args:
9
+ text (str): The text to analyze
10
+
 
11
  Returns:
12
+ dict: A dictionary containing polarity, subjectivity, and assessment
13
  """
14
+ blob = TextBlob(text)
15
+ sentiment = blob.sentiment
16
+
17
+ return {
18
+ "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
19
+ "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
20
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
21
+ }
22
 
23
+ # Create the Gradio interface
24
  demo = gr.Interface(
25
+ fn=sentiment_analysis,
26
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
27
+ outputs=gr.JSON(),
28
+ title="Text Sentiment Analysis",
29
+ description="Analyze the sentiment of text using TextBlob"
30
  )
31
 
32
+ # Launch the interface and MCP server
33
+ if __name__ == "__main__":
34
+ demo.launch(mcp_server=True)
requirements.txt CHANGED
@@ -1 +1,2 @@
1
- gradio[mcp]
 
 
1
+ "gradio[mcp]"
2
+ textblob