DSatishchandra commited on
Commit
3d3c5c6
1 Parent(s): c412ea1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -58
app.py CHANGED
@@ -1,59 +1,23 @@
1
  import gradio as gr
2
- from gtts import gTTS
3
- import os
4
-
5
- # Menu data from the second image (hardcoded for simplicity)
6
- menu = {
7
- "Appetizer": ["Veg Samosas", "Cut Mirchi", "Onion", "Spinach", "Mixed Vegetable"],
8
- "Pakodas": ["Veg Pakoda", "Chicken Pakoda", "Fish Pakoda"],
9
- "Manchurian": ["Vegetable", "Paneer", "Chicken", "Fish", "Jhinga"],
10
- "Chilly": ["Gobi", "Paneer", "Chicken", "Fish", "Shrimp"],
11
- "Chef's Special": ["Murgh (Chicken)", "Gosht (Goat)", "Jhinga (Shrimp)", "Fish Fry"],
12
- "Vegetarian Entree": ["Dal Fry", "Dal Makhani", "Channa Masala", "Aloo Gobi Masala", "Saag Paneer"],
13
- "Chettinad": ["Egg", "Murgh (Chicken)", "Gosht (Goat)", "Jhinga (Shrimp)", "Crab"],
14
- "Butter Masala": ["Chicken", "Shrimp", "Gosht (Goat)"]
15
- }
16
-
17
- # Function to speak using Google Text-to-Speech
18
- def speak(text):
19
- tts = gTTS(text=text, lang='en')
20
- tts.save("output.mp3")
21
- # Do not try to play the audio, just save it (no playback)
22
- # os.system("mpg321 output.mp3") # Removed, as it is not supported in Hugging Face
23
-
24
- # Function to process the order and handle confirmation
25
- def process_order(order, confirmation):
26
- response = "You have ordered the following: "
27
- order = order.lower()
28
-
29
- # Check for matching menu items
30
- ordered_items = []
31
- for category, items in menu.items():
32
- for item in items:
33
- if item.lower() in order:
34
- ordered_items.append(item)
35
-
36
- if ordered_items:
37
- response += ', '.join(ordered_items) + ". Is that correct?"
38
- if confirmation.lower() == "yes":
39
- speak("Thank you for your order. It will be ready shortly!")
40
- return "Order confirmed. " + response
41
- else:
42
- speak("Please tell me again what you'd like to order.")
43
- return "Order not confirmed. Please try again."
44
- else:
45
- speak("Sorry, I couldn't find any items matching your order. Can you try again?")
46
- return "Sorry, I couldn't find any items matching your order."
47
-
48
- # Create Gradio interface
49
- def start_assistant(order, confirmation):
50
- return process_order(order, confirmation)
51
-
52
- # Gradio interface setup
53
- iface = gr.Interface(fn=start_assistant, inputs=["text", "text"], outputs="text",
54
- live=True,
55
- title="Voice Food Ordering Assistant",
56
- description="Type your food order and confirm your order.")
57
-
58
- # Launch the interface
59
- iface.launch()
 
1
  import gradio as gr
2
+ import name
3
+ import asyncio
4
+
5
+ # Gradio interface function
6
+ def food_order_interface():
7
+ return name.food_order_assistant()
8
+
9
+ # Create Gradio application
10
+ async def create_demo():
11
+ demo = gr.Interface(fn=food_order_interface,
12
+ inputs=[gr.Textbox(label="Order Food", lines=2),
13
+ gr.Dropdown(choices=["Starters", "Main Course", "Desserts"], label="Food Type")],
14
+ outputs=[gr.Audio(label="Order Confirmation Audio"),
15
+ gr.Textbox(label="Confirmed Order Details", interactive=False)],
16
+ title="AI Restaurant Voice Ordering",
17
+ description="Order food easily with the AI assistant's voice ordering system.")
18
+ return demo
19
+
20
+ # Run the application
21
+ if __name__ == "__main__":
22
+ demo = asyncio.run(create_demo())
23
+ demo.launch()