redjkh commited on
Commit
5d3fb99
·
verified ·
1 Parent(s): 0b39d3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -47
app.py CHANGED
@@ -1,21 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Example fake recipe database
5
- recipes = [
6
- {
7
- "name": "Veggie Pasta",
8
- "ingredients": ["pasta", "tomato", "garlic", "olive oil"],
9
- "allergies": ["gluten"],
10
- "budget": "low"
11
- },
12
- {
13
- "name": "Chicken Stir Fry",
14
- "ingredients": ["chicken", "soy sauce", "broccoli", "garlic"],
15
- "allergies": ["soy"],
16
- "budget": "medium"
17
- }
18
- ]
19
 
20
  client = InferenceClient("microsoft/phi-4")
21
 
@@ -35,51 +20,34 @@ def respond(message, history, budget, have_items, allergies):
35
  (depending on the user's response you must respond to their request, if it is for another recipe, follow the exact same format)
36
  """
37
  messages = [{"role": "system", "content": instruction}]
38
-
39
  # Convert Gradio history (list of [user, assistant] pairs) to OpenAI-style message format
40
  for user_msg, bot_msg in history:
41
  if user_msg:
42
  messages.append({"role": "user", "content": user_msg})
43
  if bot_msg:
44
  messages.append({"role": "assistant", "content": bot_msg})
45
-
46
  # Append the new user message
47
  messages.append({"role": "user", "content": message})
48
-
49
  # Call the model
50
  response = client.chat_completion(
51
  messages=messages,
52
  max_tokens=200
53
  )
54
-
55
  return response["choices"][0]["message"]["content"].strip()
56
-
57
- """messages = [{"role": "system", "content": "You are a friendly chatbot"}]
58
- if history:
59
- messages.extend(history)
60
- messages.append({"role": "user", "content": message})
61
- response = client.chat_completion(
62
- messages,
63
- max_tokens=1000
64
- )
65
- return response['choices'][0]['message']['content'].strip()"""
66
 
67
- def update_value(value):
68
- return f"You selected: {value}"
69
  with gr.Blocks() as demo:
70
- slider = gr.Slider(
71
- minimum=0, # lowest value
72
- maximum=100, # highest value
73
- value=50, # default starting value
74
- step=1, # increment step
75
- label="Enter Budget"
76
- )
77
- output = gr.Textbox()
78
- slider.change(fn=update_value, inputs=slider, outputs=output)
79
-
80
- demo.launch()
81
-
82
-
83
- have_items = gr.Textbox(label="Ingredients you have (comma separated)", placeholder="pasta,tomato,garlic")
84
- allergies = gr.Textbox(label="Allergies (comma separated)", placeholder="gluten,soy")
85
- chatbot_ui = gr.ChatInterface(fn=lambda msg, hist: respond(msg, hist))
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  client = InferenceClient("microsoft/phi-4")
6
 
 
20
  (depending on the user's response you must respond to their request, if it is for another recipe, follow the exact same format)
21
  """
22
  messages = [{"role": "system", "content": instruction}]
 
23
  # Convert Gradio history (list of [user, assistant] pairs) to OpenAI-style message format
24
  for user_msg, bot_msg in history:
25
  if user_msg:
26
  messages.append({"role": "user", "content": user_msg})
27
  if bot_msg:
28
  messages.append({"role": "assistant", "content": bot_msg})
 
29
  # Append the new user message
30
  messages.append({"role": "user", "content": message})
 
31
  # Call the model
32
  response = client.chat_completion(
33
  messages=messages,
34
  max_tokens=200
35
  )
 
36
  return response["choices"][0]["message"]["content"].strip()
 
 
 
 
 
 
 
 
 
 
37
 
 
 
38
  with gr.Blocks() as demo:
39
+ gr.Markdown("## :fried_egg: Recipe Suggestion Chatbot")
40
+ with gr.Tab("Your resources: "):
41
+ budget = gr.Slider(
42
+ minimum=0, # lowest value
43
+ maximum=100, # highest value
44
+ value=50, # default starting value
45
+ step=1, # increment step
46
+ label="Enter Budget:"
47
+ )
48
+ have_items = gr.Textbox(label="Ingredients you have (comma separated)", placeholder="pasta,tomato,garlic")
49
+ allergies = gr.Textbox(label="Allergies (comma separated)", placeholder="gluten,soy")
50
+ with gr.Tab("Talk with recipEASY! "):
51
+ chatbot_ui = gr.ChatInterface(fn=lambda msg, hist, budget, have_items, allergies: respond(msg, hist, budget, have_items, allergies))
52
+
53
+ demo.launch()