Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import numpy as np
|
|
3 |
import sqlite3
|
4 |
import json
|
5 |
from PIL import Image, ImageDraw
|
|
|
6 |
|
7 |
# ------ Tool Implementations ------
|
8 |
def get_recipe_by_ingredients(ingredients):
|
@@ -98,19 +99,14 @@ def process_query(query, db_conn):
|
|
98 |
}
|
99 |
|
100 |
# ------ Gradio Interface ------
|
101 |
-
def
|
102 |
-
"""Process
|
103 |
-
# For demo purposes, we'll use text input directly
|
104 |
-
# In a real implementation, this would convert audio to text
|
105 |
-
sample_rate, audio_data = audio
|
106 |
-
query = "What can I make with eggs and flour?" # Fixed for demo
|
107 |
-
|
108 |
# Initialize database on first run
|
109 |
-
if not hasattr(
|
110 |
-
|
111 |
|
112 |
# Process query
|
113 |
-
result = process_query(query,
|
114 |
|
115 |
# Generate response
|
116 |
response_text = ""
|
@@ -134,25 +130,39 @@ def process_voice_command(audio):
|
|
134 |
for recipe in recipes:
|
135 |
response_text += f"- {recipe[1]} ({recipe[4]} mins)\n"
|
136 |
|
137 |
-
# Return results
|
138 |
-
return
|
139 |
|
140 |
# ------ Create Gradio Interface ------
|
141 |
-
with gr.Blocks(title="Culinary
|
142 |
-
gr.Markdown("# π§βπ³ MCP-Powered Culinary
|
143 |
|
144 |
with gr.Row():
|
145 |
-
|
|
|
|
|
146 |
with gr.Column():
|
147 |
text_output = gr.Textbox(label="Assistant Response", interactive=False)
|
148 |
image_output = gr.Image(label="Recipe Image", interactive=False)
|
149 |
|
150 |
-
submit_btn = gr.Button("Process Command", variant="primary")
|
151 |
-
|
152 |
submit_btn.click(
|
153 |
-
fn=
|
154 |
-
inputs=[
|
155 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
)
|
157 |
|
158 |
if __name__ == "__main__":
|
|
|
3 |
import sqlite3
|
4 |
import json
|
5 |
from PIL import Image, ImageDraw
|
6 |
+
import time
|
7 |
|
8 |
# ------ Tool Implementations ------
|
9 |
def get_recipe_by_ingredients(ingredients):
|
|
|
99 |
}
|
100 |
|
101 |
# ------ Gradio Interface ------
|
102 |
+
def process_command(query):
|
103 |
+
"""Process text command"""
|
|
|
|
|
|
|
|
|
|
|
104 |
# Initialize database on first run
|
105 |
+
if not hasattr(process_command, "db_conn"):
|
106 |
+
process_command.db_conn = init_recipe_db()
|
107 |
|
108 |
# Process query
|
109 |
+
result = process_query(query, process_command.db_conn)
|
110 |
|
111 |
# Generate response
|
112 |
response_text = ""
|
|
|
130 |
for recipe in recipes:
|
131 |
response_text += f"- {recipe[1]} ({recipe[4]} mins)\n"
|
132 |
|
133 |
+
# Return results
|
134 |
+
return response_text, image
|
135 |
|
136 |
# ------ Create Gradio Interface ------
|
137 |
+
with gr.Blocks(title="Culinary Assistant") as demo:
|
138 |
+
gr.Markdown("# π§βπ³ MCP-Powered Culinary Assistant")
|
139 |
|
140 |
with gr.Row():
|
141 |
+
with gr.Column():
|
142 |
+
text_input = gr.Textbox(label="Ask about recipes, conversions, or cooking tips")
|
143 |
+
submit_btn = gr.Button("Get Answer", variant="primary")
|
144 |
with gr.Column():
|
145 |
text_output = gr.Textbox(label="Assistant Response", interactive=False)
|
146 |
image_output = gr.Image(label="Recipe Image", interactive=False)
|
147 |
|
|
|
|
|
148 |
submit_btn.click(
|
149 |
+
fn=process_command,
|
150 |
+
inputs=[text_input],
|
151 |
+
outputs=[text_output, image_output]
|
152 |
+
)
|
153 |
+
|
154 |
+
gr.Examples(
|
155 |
+
examples=[
|
156 |
+
["What can I make with eggs and flour?"],
|
157 |
+
["Show me tomato soup"],
|
158 |
+
["Convert 2 cups to milliliters"],
|
159 |
+
["Find chocolate cake recipes"]
|
160 |
+
],
|
161 |
+
inputs=[text_input],
|
162 |
+
outputs=[text_output, image_output],
|
163 |
+
fn=process_command,
|
164 |
+
cache_examples=True,
|
165 |
+
label="Example Queries"
|
166 |
)
|
167 |
|
168 |
if __name__ == "__main__":
|