codejedi commited on
Commit
0fb21a5
·
1 Parent(s): f0b4229

export GRADIO_MCP_SERVER=True

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