Update app.py
Browse files
app.py
CHANGED
|
@@ -2,36 +2,33 @@ import json
|
|
| 2 |
import gradio as gr
|
| 3 |
from textblob import TextBlob
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
-
|
| 8 |
|
| 9 |
Args:
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
Returns:
|
| 13 |
-
|
| 14 |
"""
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 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 |
-
return json.dumps(result)
|
| 25 |
|
| 26 |
-
# Create
|
| 27 |
demo = gr.Interface(
|
| 28 |
-
fn=
|
| 29 |
-
inputs=
|
| 30 |
-
outputs=
|
| 31 |
-
title="
|
| 32 |
-
description="
|
| 33 |
)
|
| 34 |
|
| 35 |
-
# Launch the interface and MCP server
|
| 36 |
if __name__ == "__main__":
|
| 37 |
demo.launch(mcp_server=True)
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from textblob import TextBlob
|
| 4 |
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
def letter_counter(word: str, letter: str) -> int:
|
| 8 |
"""
|
| 9 |
+
Count the number of occurrences of a letter in a word or text.
|
| 10 |
|
| 11 |
Args:
|
| 12 |
+
word (str): The input text to search through
|
| 13 |
+
letter (str): The letter to search for
|
| 14 |
|
| 15 |
Returns:
|
| 16 |
+
int: The number of times the letter appears in the text
|
| 17 |
"""
|
| 18 |
+
word = word.lower()
|
| 19 |
+
letter = letter.lower()
|
| 20 |
+
count = word.count(letter)
|
| 21 |
+
return count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Create a standard Gradio interface
|
| 24 |
demo = gr.Interface(
|
| 25 |
+
fn=letter_counter,
|
| 26 |
+
inputs=["textbox", "textbox"],
|
| 27 |
+
outputs="number",
|
| 28 |
+
title="Letter Counter",
|
| 29 |
+
description="Enter text and a letter to count how many times the letter appears in the text."
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Launch both the Gradio web interface and the MCP server
|
| 33 |
if __name__ == "__main__":
|
| 34 |
demo.launch(mcp_server=True)
|