Spaces:
Sleeping
Sleeping
serichard1
commited on
Commit
·
92f51ec
1
Parent(s):
9c1c25e
Add application file
Browse files- README copy.md +15 -0
- app.py +41 -0
- requirements.txt +1 -0
README copy.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Hackathon Mcp Lexicon
|
| 3 |
+
emoji: 💬
|
| 4 |
+
colorFrom: yellow
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.42.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
hf_oauth: true
|
| 11 |
+
hf_oauth_scopes:
|
| 12 |
+
- inference-api
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def get_random_quote(lang='en', format='json'):
|
| 5 |
+
"""
|
| 6 |
+
Fetches a random quote from the Forismatic API.
|
| 7 |
+
|
| 8 |
+
Args:
|
| 9 |
+
lang (str): Language code for the quote. Default is 'en'.
|
| 10 |
+
format (str): Response format. Default is 'json'.
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
str: Formatted quote string with author.
|
| 14 |
+
"""
|
| 15 |
+
url = "http://api.forismatic.com/api/1.0/"
|
| 16 |
+
params = {
|
| 17 |
+
'method': 'getQuote',
|
| 18 |
+
'lang': lang,
|
| 19 |
+
'format': format
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
response = requests.get(url, params=params)
|
| 23 |
+
response.raise_for_status()
|
| 24 |
+
data = response.json()
|
| 25 |
+
|
| 26 |
+
quote = data.get('quoteText', 'No quote available').strip()
|
| 27 |
+
author = data.get('quoteAuthor', 'Unknown').strip()
|
| 28 |
+
|
| 29 |
+
return f'"{quote}"\n— {author}'
|
| 30 |
+
|
| 31 |
+
# Create Gradio interface
|
| 32 |
+
app = gr.Interface(
|
| 33 |
+
fn=get_random_quote,
|
| 34 |
+
inputs=[], # no input needed
|
| 35 |
+
outputs=gr.Textbox(label="Random Quote"),
|
| 36 |
+
title="Random Quote Generator",
|
| 37 |
+
description="Click the button to get an inspiring random quote."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
app.launch(mcp_server=True, share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|