| import json |
| import gradio as gr |
| import random |
|
|
| |
| with open("gift_ideas.json") as f: |
| gift_ideas = json.load(f) |
|
|
| def gift_chatbot(user_input): |
| user_input = user_input.lower() |
| matching = [f"{title} — {link}" for title, link in gift_ideas if user_input in title.lower()] |
| |
| if matching: |
| return random.choice(matching) |
| else: |
| return "Hmm... I couldn't find a gift for that. Try a different keyword like 'kitchen' or 'funny'." |
|
|
| chatbot = gr.Interface( |
| fn=gift_chatbot, |
| inputs=gr.Textbox(label="What kind of gift are you looking for?"), |
| outputs=gr.Textbox(label="Gift idea:"), |
| title="🎁 Gift Bot", |
| description="Enter a theme or keyword and get a unique gift idea!" |
| ) |
|
|
| chatbot.launch() |
|
|