DSatishchandra commited on
Commit
b0c4baa
1 Parent(s): 7c354b2

Update order_assistant.py

Browse files
Files changed (1) hide show
  1. order_assistant.py +11 -14
order_assistant.py CHANGED
@@ -1,21 +1,18 @@
1
- import gradio as gr
 
2
  import speech_recognition as sr
3
  import edge_tts
4
  import asyncio
5
- import random
6
  import tempfile
7
 
8
- # Example food menu
9
- food_menu = {
10
- "Starters": ["Spring Rolls", "Samosa", "Garlic Bread"],
11
- "Main Course": ["Biryani", "Pizza", "Pasta", "Butter Chicken"],
12
- "Desserts": ["Ice Cream", "Gulab Jamun", "Chocolate Cake"]
13
- }
14
 
15
- # Function to simulate food suggestions based on user input
16
- def get_food_suggestion(food_type):
17
  if food_type in food_menu:
18
- return random.choice(food_menu[food_type])
19
  return "No suggestion available"
20
 
21
  # Speech-to-Text function
@@ -40,14 +37,14 @@ async def text_to_speech(text):
40
  return tmp_path
41
 
42
  # AI Food Ordering Assistant Function
43
- async def food_order_assistant():
44
  # Greeting
45
  greeting_text = "Welcome to the restaurant! Please tell me your food preference."
46
  audio_path = await text_to_speech(greeting_text)
47
 
48
  # Wait for user to input food type
49
- user_food_type = recognize_speech_from_mic()
50
- suggestion = get_food_suggestion(user_food_type)
51
 
52
  suggestion_text = f"I suggest you try {suggestion}."
53
  suggestion_audio = await text_to_speech(suggestion_text)
 
1
+ import json
2
+ import random
3
  import speech_recognition as sr
4
  import edge_tts
5
  import asyncio
 
6
  import tempfile
7
 
8
+ # Load the food menu from menu.json
9
+ with open("menu.json") as f:
10
+ food_menu = json.load(f)
 
 
 
11
 
12
+ # Function to get food suggestions based on user input
13
+ def get_food_suggestion(food_type, filter_type):
14
  if food_type in food_menu:
15
+ return random.choice(food_menu[food_type].get(filter_type, []))
16
  return "No suggestion available"
17
 
18
  # Speech-to-Text function
 
37
  return tmp_path
38
 
39
  # AI Food Ordering Assistant Function
40
+ async def food_order_assistant(text_input, food_type):
41
  # Greeting
42
  greeting_text = "Welcome to the restaurant! Please tell me your food preference."
43
  audio_path = await text_to_speech(greeting_text)
44
 
45
  # Wait for user to input food type
46
+ filter_type = text_input.lower() # Assuming the input is the filter type (vegan, halal, etc.)
47
+ suggestion = get_food_suggestion(food_type, filter_type)
48
 
49
  suggestion_text = f"I suggest you try {suggestion}."
50
  suggestion_audio = await text_to_speech(suggestion_text)