mgbam commited on
Commit
84e7ad3
Β·
verified Β·
1 Parent(s): a367b14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -20
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 process_voice_command(audio):
102
- """Process voice command"""
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(process_voice_command, "db_conn"):
110
- process_voice_command.db_conn = init_recipe_db()
111
 
112
  # Process query
113
- result = process_query(query, process_voice_command.db_conn)
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 (no audio in this simplified version)
138
- return None, response_text, image
139
 
140
  # ------ Create Gradio Interface ------
141
- with gr.Blocks(title="Culinary Voice Assistant") as demo:
142
- gr.Markdown("# πŸ§‘β€πŸ³ MCP-Powered Culinary Voice Assistant")
143
 
144
  with gr.Row():
145
- audio_input = gr.Audio(source="microphone", type="numpy", label="Speak to Chef")
 
 
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=process_voice_command,
154
- inputs=[audio_input],
155
- outputs=[gr.Audio(visible=False), text_output, image_output]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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__":