DSatishchandra commited on
Commit
aa30635
·
verified ·
1 Parent(s): 1c65dd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -26
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from gtts import gTTS
2
  import os
3
 
@@ -17,14 +18,7 @@ menu = {
17
  def speak(text):
18
  tts = gTTS(text=text, lang='en')
19
  tts.save("output.mp3")
20
- os.system("mpg321 output.mp3") # This line can be removed as it's not needed on Hugging Face
21
-
22
- # Simulate listening by using text input (for Hugging Face)
23
- def listen():
24
- # For testing on Hugging Face, simulate listening by getting text input
25
- print("Please type your order below:")
26
- order = input("Your order: ")
27
- return order
28
 
29
  # Function to process the order
30
  def process_order(order):
@@ -41,25 +35,17 @@ def process_order(order):
41
  if ordered_items:
42
  response += ', '.join(ordered_items) + ". Is that correct?"
43
  speak(response)
44
- confirmation = listen()
45
- if "yes" in confirmation.lower():
46
- speak("Thank you for your order. It will be ready shortly!")
47
- else:
48
- speak("Please tell me again what you'd like to order.")
49
  else:
50
  speak("Sorry, I couldn't find any items matching your order. Can you try again?")
 
 
 
 
 
51
 
52
- # Main function to start the assistant
53
- def start_assistant():
54
- speak("Welcome to the Voice Food Ordering Assistant!")
55
- speak("What would you like to order today?")
56
- while True:
57
- order = listen()
58
- if order:
59
- process_order(order)
60
- else:
61
- speak("Sorry, I didn't catch that.")
62
 
63
- # Run the assistant
64
- if __name__ == "__main__":
65
- start_assistant()
 
1
+ import gradio as gr
2
  from gtts import gTTS
3
  import os
4
 
 
18
  def speak(text):
19
  tts = gTTS(text=text, lang='en')
20
  tts.save("output.mp3")
21
+ os.system("mpg321 output.mp3") # This can be omitted for environments like Hugging Face that don't support audio
 
 
 
 
 
 
 
22
 
23
  # Function to process the order
24
  def process_order(order):
 
35
  if ordered_items:
36
  response += ', '.join(ordered_items) + ". Is that correct?"
37
  speak(response)
38
+ return response
 
 
 
 
39
  else:
40
  speak("Sorry, I couldn't find any items matching your order. Can you try again?")
41
+ return "Sorry, I couldn't find any items matching your order. Can you try again?"
42
+
43
+ # Create Gradio interface
44
+ def start_assistant(order):
45
+ return process_order(order)
46
 
47
+ # Gradio interface setup
48
+ iface = gr.Interface(fn=start_assistant, inputs=gr.Textbox(label="Type your order"), outputs="text")
 
 
 
 
 
 
 
 
49
 
50
+ # Launch the interface
51
+ iface.launch()