redjkh commited on
Commit
66915c2
·
verified ·
1 Parent(s): dcbbbe4

Create app.py

Browse files

copied from thingy

Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ # model!
5
+ MODEL_NAME = "HuggingFaceH4/zephyr-7b-beta"
6
+
7
+ client = InferenceClient(model=MODEL_NAME)
8
+
9
+ # Example fake recipe database
10
+ recipes = [
11
+ {
12
+ "name": "Veggie Pasta",
13
+ "ingredients": ["pasta", "tomato", "garlic", "olive oil"],
14
+ "allergies": ["gluten"],
15
+ "budget": "low"
16
+ },
17
+ {
18
+ "name": "Chicken Stir Fry",
19
+ "ingredients": ["chicken", "soy sauce", "broccoli", "garlic"],
20
+ "allergies": ["soy"],
21
+ "budget": "medium"
22
+ }
23
+ ]
24
+
25
+ client = InferenceClient("microsoft/phi-4")
26
+
27
+ def respond(message, history):
28
+ messages = [{"role": "system", "content": "You are a friendly chatbot"}]
29
+ if history:
30
+ messages.extend(history)
31
+ messages.append({"role": "user", "content": message})
32
+
33
+ response = client.chat_completion(
34
+ messages,
35
+ max_tokens=100
36
+ )
37
+
38
+ return response['choices'][0]['message']['content'].strip()
39
+
40
+
41
+ with gr.Blocks() as demo:
42
+ gr.Markdown("## 🍳 Recipe Suggestion Chatbot")
43
+
44
+ budget = gr.Dropdown(["low", "medium", "high"], label="Budget", value="low")
45
+ have_items = gr.Textbox(label="Ingredients you have (comma separated)", placeholder="pasta,tomato,garlic")
46
+ allergies = gr.Textbox(label="Allergies (comma separated)", placeholder="gluten,soy")
47
+ chatbot_ui = gr.ChatInterface(fn=lambda msg, hist: respond(msg, hist))
48
+
49
+ demo.launch()