Update app.py
Browse files
app.py
CHANGED
|
@@ -22,37 +22,21 @@ recipes = [
|
|
| 22 |
}
|
| 23 |
]
|
| 24 |
|
| 25 |
-
|
| 26 |
-
results = []
|
| 27 |
-
for recipe in recipes:
|
| 28 |
-
if recipe["budget"] != budget:
|
| 29 |
-
continue
|
| 30 |
-
if any(a in recipe["allergies"] for a in allergies):
|
| 31 |
-
continue
|
| 32 |
-
if not all(item in have_items for item in recipe["ingredients"]):
|
| 33 |
-
continue
|
| 34 |
-
results.append(recipe["name"])
|
| 35 |
-
return results or ["No matching recipes found."]
|
| 36 |
|
| 37 |
-
def
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
f"Suggest recipes from this list: {recipes_found}."
|
| 43 |
-
)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
msgs.append({"role": "user", "content": message})
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
token = resp.choices[0].delta.content or ""
|
| 54 |
-
response_text += token
|
| 55 |
-
yield response_text
|
| 56 |
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
gr.Markdown("## 🍳 Recipe Suggestion Chatbot")
|
|
@@ -60,6 +44,6 @@ with gr.Blocks() as demo:
|
|
| 60 |
budget = gr.Dropdown(["low", "medium", "high"], label="Budget", value="low")
|
| 61 |
have_items = gr.Textbox(label="Ingredients you have (comma separated)", placeholder="pasta,tomato,garlic")
|
| 62 |
allergies = gr.Textbox(label="Allergies (comma separated)", placeholder="gluten,soy")
|
| 63 |
-
chatbot_ui = gr.ChatInterface(fn=lambda msg, hist:
|
| 64 |
|
| 65 |
demo.launch()
|
|
|
|
| 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")
|
|
|
|
| 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()
|