Spaces:
Build error
Build error
DSatishchandra
commited on
Commit
•
82555d7
1
Parent(s):
9ef80fc
Update order_assistant.py
Browse files- order_assistant.py +19 -12
order_assistant.py
CHANGED
@@ -22,7 +22,7 @@ def recognize_speech_from_mic():
|
|
22 |
print("Say something!")
|
23 |
audio = recognizer.listen(source)
|
24 |
try:
|
25 |
-
return recognizer.recognize_google(audio)
|
26 |
except sr.UnknownValueError:
|
27 |
return "Sorry I didn't catch that"
|
28 |
except sr.RequestError:
|
@@ -37,23 +37,30 @@ async def text_to_speech(text):
|
|
37 |
return tmp_path
|
38 |
|
39 |
# AI Food Ordering Assistant Function
|
40 |
-
async def food_order_assistant(
|
41 |
-
# Greeting
|
42 |
-
greeting_text = "Welcome to the restaurant!
|
43 |
audio_path = await text_to_speech(greeting_text)
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
suggestion = get_food_suggestion(food_type, filter_type)
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
suggestion_audio = await text_to_speech(suggestion_text)
|
51 |
|
52 |
-
# Wait for confirmation
|
53 |
-
confirmation = recognize_speech_from_mic()
|
54 |
-
|
55 |
-
|
|
|
56 |
confirmation_audio = await text_to_speech(confirmation_text)
|
|
|
57 |
return confirmation_audio, f"Confirmed order: {suggestion}"
|
58 |
else:
|
59 |
cancellation_text = "Okay, let's try again."
|
|
|
22 |
print("Say something!")
|
23 |
audio = recognizer.listen(source)
|
24 |
try:
|
25 |
+
return recognizer.recognize_google(audio) # Use Google Speech Recognition
|
26 |
except sr.UnknownValueError:
|
27 |
return "Sorry I didn't catch that"
|
28 |
except sr.RequestError:
|
|
|
37 |
return tmp_path
|
38 |
|
39 |
# AI Food Ordering Assistant Function
|
40 |
+
async def food_order_assistant(audio_input, food_type):
|
41 |
+
# Greeting and introduction
|
42 |
+
greeting_text = "Welcome to the restaurant! What would you like to order today? Are you looking for Vegan, Halal, or Guilt-Free options?"
|
43 |
audio_path = await text_to_speech(greeting_text)
|
44 |
|
45 |
+
# Recognize customer's preference (Vegan, Halal, Guilt-Free)
|
46 |
+
dietary_preference = recognize_speech_from_mic().lower()
|
|
|
47 |
|
48 |
+
if dietary_preference not in ["vegan", "halal", "guilt-free"]:
|
49 |
+
dietary_preference = "vegan" # Default to Vegan if unrecognized
|
50 |
+
|
51 |
+
# Get food suggestion based on preference
|
52 |
+
suggestion = get_food_suggestion(food_type, dietary_preference)
|
53 |
+
|
54 |
+
suggestion_text = f"I suggest you try {suggestion}. Does that sound good?"
|
55 |
suggestion_audio = await text_to_speech(suggestion_text)
|
56 |
|
57 |
+
# Wait for customer confirmation
|
58 |
+
confirmation = recognize_speech_from_mic().lower()
|
59 |
+
|
60 |
+
if "yes" in confirmation:
|
61 |
+
confirmation_text = f"Your order for {suggestion} has been confirmed. Sending the order to the kitchen."
|
62 |
confirmation_audio = await text_to_speech(confirmation_text)
|
63 |
+
# Simulate sending order to kitchen
|
64 |
return confirmation_audio, f"Confirmed order: {suggestion}"
|
65 |
else:
|
66 |
cancellation_text = "Okay, let's try again."
|