Spaces:
Sleeping
Sleeping
sys
Browse files
app.py
CHANGED
|
@@ -5,8 +5,54 @@ client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
|
|
| 5 |
|
| 6 |
|
| 7 |
def respond(message, history):
|
| 8 |
-
messages = [{"role": "system", "content": "You are a
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
if history:
|
| 11 |
messages.extend(history)
|
| 12 |
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def respond(message, history):
|
| 8 |
+
messages = [{"role": "system", "content": "You have the personality of Lee Know from Straykids. You are a recipe assistant who suggests recipies based on the
|
| 9 |
+
the ingredients the user has and their dietary restrictions."
|
| 10 |
+
}]
|
| 11 |
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# "role": "system",
|
| 15 |
+
# "content": """You are a recipe assistant. You MUST respond using ONLY this exact format, no exceptions:
|
| 16 |
+
# 🍽️ Dish: Spinach and Egg Scramble
|
| 17 |
+
# ⏱️ Time: 5 min prep, 10 min cook
|
| 18 |
+
# 🛒 Ingredients: 2 eggs, 1 cup spinach, salt, pepper, olive oil
|
| 19 |
+
# 👨🍳 Steps: 1. Heat oil. 2. Sauté spinach 2 min. 3. Add eggs, scramble until set.
|
| 20 |
+
# 💡 Tip: Add feta cheese for extra flavor.
|
| 21 |
+
# Suggest ONE recipe only. If asked about non-food topics, say: 'I only know recipes!'"""
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# "You are a friendly recipe assistant and home chef. Your job is to suggest simple, tasty recipes based on the ingredients
|
| 25 |
+
# the user already has. Keep each response under 120 words. Use this format: Recipe: <name> Ingredients: <list> Steps: <2-4 short steps>.
|
| 26 |
+
# Prefer recipes that use mostly the user's ingredients, suggest at most 2 extra common ingredients if needed, and keep instructions easy for
|
| 27 |
+
# beginners. Example: If the user says 'eggs, bread, cheese,' suggest a recipe like a cheesy egg toast with short steps."
|
| 28 |
+
}
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
if history:
|
| 32 |
+
messages.extend(history)
|
| 33 |
+
|
| 34 |
+
messages.append({"role": "user", "content": message})
|
| 35 |
+
|
| 36 |
+
response = ""
|
| 37 |
+
|
| 38 |
+
for chunk in client.chat_completion(
|
| 39 |
+
messages=messages,
|
| 40 |
+
max_tokens=300,
|
| 41 |
+
temperature=0.7,
|
| 42 |
+
top_p=0.9,
|
| 43 |
+
stream=True
|
| 44 |
+
):
|
| 45 |
+
token = chunk.choices[0].delta.content
|
| 46 |
+
if token:
|
| 47 |
+
response += token
|
| 48 |
+
yield response
|
| 49 |
+
|
| 50 |
+
chatbot = gr.ChatInterface(respond)
|
| 51 |
+
|
| 52 |
+
chatbot.launch()
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
if history:
|
| 57 |
messages.extend(history)
|
| 58 |
|