Samilincoln commited on
Commit ·
20514e9
1
Parent(s): 27e1e75
changed type to chat to resolve memory issue
Browse files
app.py
CHANGED
|
@@ -31,15 +31,31 @@ json_data = food_data.to_json(orient="records", lines=False, indent=4)
|
|
| 31 |
with open(json_path, "w") as json_file:
|
| 32 |
json_file.write(json_data)
|
| 33 |
|
| 34 |
-
few_shot_prompt = f"
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return response.text
|
| 39 |
|
| 40 |
bot = gr.ChatInterface(
|
| 41 |
fn=recipe_chatbot,
|
| 42 |
-
type="
|
|
|
|
|
|
|
| 43 |
)
|
| 44 |
|
| 45 |
bot.launch()
|
|
|
|
| 31 |
with open(json_path, "w") as json_file:
|
| 32 |
json_file.write(json_data)
|
| 33 |
|
| 34 |
+
few_shot_prompt = f"""
|
| 35 |
+
You are an interactive recipe assistant. Use the following dataset to recommend recipes:
|
| 36 |
+
{json_data}
|
| 37 |
+
|
| 38 |
+
Instructions:
|
| 39 |
+
1. Provide recipes based on the user's query.
|
| 40 |
+
2. If the requested recipe is unavailable, suggest the most similar one.
|
| 41 |
+
3. Maintain context across multiple messages.
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
history = []
|
| 45 |
+
def recipe_chatbot(messages: str, history: list[str]):
|
| 46 |
+
ask = {
|
| 47 |
+
"current message" : messages,
|
| 48 |
+
"previous message": history[::-1]
|
| 49 |
+
}
|
| 50 |
+
history.append(messages)
|
| 51 |
+
response = model.generate_content([few_shot_prompt,ask], request_options=retry_policy)
|
| 52 |
return response.text
|
| 53 |
|
| 54 |
bot = gr.ChatInterface(
|
| 55 |
fn=recipe_chatbot,
|
| 56 |
+
type="chat",
|
| 57 |
+
title="Kitcher - The recipe Assistant",
|
| 58 |
+
description="Ask me about Nigerian dishes and I'll provide recipes or similar dish suggestions!",
|
| 59 |
)
|
| 60 |
|
| 61 |
bot.launch()
|