Spaces:
Sleeping
Sleeping
Commit
·
bf91d2a
1
Parent(s):
16d62e2
✨ Update Joke function to accept type parameter and modify Gradio interface for joke selection
Browse files
app.py
CHANGED
@@ -146,12 +146,14 @@ def Ping(Host: str, Count: int = 8) -> str:
|
|
146 |
# │ Fun and Entertainment Tools │
|
147 |
# ╰───────────────────────────────────╯
|
148 |
|
149 |
-
def Joke() -> str:
|
150 |
'''Get a random joke.
|
|
|
|
|
151 |
Returns:
|
152 |
str: A random joke.
|
153 |
'''
|
154 |
-
return requests.get('https://v2.jokeapi.dev/joke/
|
155 |
|
156 |
def Fact() -> str:
|
157 |
'''Get a random fact.
|
@@ -390,8 +392,9 @@ with gradio.Blocks(
|
|
390 |
with gradio.TabItem('Random Joke 😂'):
|
391 |
with gradio.Group():
|
392 |
JokeOutput = gradio.Text(label='Random Joke 😂', interactive=False)
|
|
|
393 |
JokeBtn = gradio.Button('Get Joke 🎪', variant='primary')
|
394 |
-
JokeBtn.click(Joke, outputs=JokeOutput)
|
395 |
|
396 |
with gradio.TabItem('Random Fact 🧠'):
|
397 |
with gradio.Group():
|
|
|
146 |
# │ Fun and Entertainment Tools │
|
147 |
# ╰───────────────────────────────────╯
|
148 |
|
149 |
+
def Joke(Type: Literal['Any', 'Programming', 'Misc', 'Dark', 'Pun', 'Spooky', 'Christmas']) -> str:
|
150 |
'''Get a random joke.
|
151 |
+
Args:
|
152 |
+
Type (Literal['Any', 'Programming', 'Misc', 'Dark', 'Pun', 'Spooky', 'Christmas']): The type of joke to fetch.
|
153 |
Returns:
|
154 |
str: A random joke.
|
155 |
'''
|
156 |
+
return requests.get(f'https://v2.jokeapi.dev/joke/{Type}?format=txt').text
|
157 |
|
158 |
def Fact() -> str:
|
159 |
'''Get a random fact.
|
|
|
392 |
with gradio.TabItem('Random Joke 😂'):
|
393 |
with gradio.Group():
|
394 |
JokeOutput = gradio.Text(label='Random Joke 😂', interactive=False)
|
395 |
+
JokeType = gradio.Radio(label='Joke Type 🤡', choices=['Any', 'Programming', 'Misc', 'Dark', 'Pun', 'Spooky', 'Christmas'], value='Any', interactive=True)
|
396 |
JokeBtn = gradio.Button('Get Joke 🎪', variant='primary')
|
397 |
+
JokeBtn.click(Joke, inputs=[JokeType], outputs=JokeOutput)
|
398 |
|
399 |
with gradio.TabItem('Random Fact 🧠'):
|
400 |
with gradio.Group():
|