Gianpaolo Macario
feat(app): add get_dad_joke()
d0ce3d8
raw
history blame
850 Bytes
import gradio as gr
import requests
def greet(name: str) -> str:
"""
Greets the user with a personalized hello message.
Args:
name (str): The name of the user to greet.
Returns:
str: A greeting message addressed to the specified user.
"""
if not name:
return "Hello stranger!!"
name = name.strip()
if len(name) > 50:
return "Name is too long!"
return "Hello " + name + "!!"
def get_dad_joke():
headers = {"Accept": "application/json"}
response = requests.get("https://icanhazdadjoke.com/", headers=headers)
if response.status_code == 200:
data = response.json()
return data.get("joke", "No joke found.")
else:
return "Failed to retrieve a joke."
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch(mcp_server=True)