Gianpaolo Macario
commited on
Commit
·
d0ce3d8
1
Parent(s):
ff2f8a3
feat(app): add get_dad_joke()
Browse filesCredits: https://huggingface.co/spaces/Agents-MCP-Hackathon/llm-can-tell-funny-jokes
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
def greet(name: str) -> str:
|
| 4 |
"""
|
|
@@ -15,5 +16,14 @@ def greet(name: str) -> str:
|
|
| 15 |
return "Name is too long!"
|
| 16 |
return "Hello " + name + "!!"
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 19 |
demo.launch(mcp_server=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
def greet(name: str) -> str:
|
| 5 |
"""
|
|
|
|
| 16 |
return "Name is too long!"
|
| 17 |
return "Hello " + name + "!!"
|
| 18 |
|
| 19 |
+
def get_dad_joke():
|
| 20 |
+
headers = {"Accept": "application/json"}
|
| 21 |
+
response = requests.get("https://icanhazdadjoke.com/", headers=headers)
|
| 22 |
+
if response.status_code == 200:
|
| 23 |
+
data = response.json()
|
| 24 |
+
return data.get("joke", "No joke found.")
|
| 25 |
+
else:
|
| 26 |
+
return "Failed to retrieve a joke."
|
| 27 |
+
|
| 28 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 29 |
demo.launch(mcp_server=True)
|