Spaces:
Sleeping
Sleeping
Daniel Ecer commited on
Commit ·
e37f322
1
Parent(s): 48b14a1
Added zenquotes
Browse files
fngradio_various_api_mcp/apis/zenquotes.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fngradio import FnGradioApp
|
| 2 |
+
import httpx
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
app = FnGradioApp()
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@app.interface()
|
| 9 |
+
def get_random_zen_quote() -> str:
|
| 10 |
+
"""
|
| 11 |
+
Get random quote from `zenquotes.io`
|
| 12 |
+
"""
|
| 13 |
+
response = httpx.get('https://zenquotes.io/api/random')
|
| 14 |
+
response.raise_for_status()
|
| 15 |
+
response_json = response.json()
|
| 16 |
+
try:
|
| 17 |
+
if not response_json:
|
| 18 |
+
return 'No quote available'
|
| 19 |
+
quote_json = response_json[0]
|
| 20 |
+
quote = quote_json['q']
|
| 21 |
+
author = quote_json['a']
|
| 22 |
+
return f'Quote: {quote}\nAuthor: {author}'
|
| 23 |
+
except TypeError:
|
| 24 |
+
return f'Failed to process response: {response_json}'
|
fngradio_various_api_mcp/app.py
CHANGED
|
@@ -3,12 +3,14 @@ from fngradio import FnGradioApp
|
|
| 3 |
from fngradio_various_api_mcp.apis import (
|
| 4 |
catfact,
|
| 5 |
jokeapi,
|
| 6 |
-
numbersapi
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
|
| 10 |
app = FnGradioApp(apps=[
|
| 11 |
catfact.app,
|
| 12 |
jokeapi.app,
|
| 13 |
-
numbersapi.app
|
|
|
|
| 14 |
])
|
|
|
|
| 3 |
from fngradio_various_api_mcp.apis import (
|
| 4 |
catfact,
|
| 5 |
jokeapi,
|
| 6 |
+
numbersapi,
|
| 7 |
+
zenquotes
|
| 8 |
)
|
| 9 |
|
| 10 |
|
| 11 |
app = FnGradioApp(apps=[
|
| 12 |
catfact.app,
|
| 13 |
jokeapi.app,
|
| 14 |
+
numbersapi.app,
|
| 15 |
+
zenquotes.app
|
| 16 |
])
|