Update app.py
Browse files
app.py
CHANGED
|
@@ -1,72 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
nlp_pipeline = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 12 |
-
|
| 13 |
-
# Define Menu
|
| 14 |
-
MENU = {
|
| 15 |
-
"biryani": 200,
|
| 16 |
-
"naan": 50,
|
| 17 |
-
"curry": 150,
|
| 18 |
-
"paneer": 180,
|
| 19 |
-
"samosa": 20,
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
# Speech-to-Text Function
|
| 23 |
-
def speech_to_text(audio):
|
| 24 |
-
try:
|
| 25 |
-
audio_path = audio
|
| 26 |
-
result = model.transcribe(audio_path)
|
| 27 |
-
return result["text"]
|
| 28 |
-
except Exception as e:
|
| 29 |
-
return f"Error: {str(e)}"
|
| 30 |
-
|
| 31 |
-
# Process Order and Generate Response
|
| 32 |
-
def process_order(transcription):
|
| 33 |
-
items = []
|
| 34 |
-
total_cost = 0
|
| 35 |
-
|
| 36 |
-
for item in MENU.keys():
|
| 37 |
-
if item in transcription.lower():
|
| 38 |
-
items.append(item)
|
| 39 |
-
total_cost += MENU[item]
|
| 40 |
-
|
| 41 |
-
if items:
|
| 42 |
-
response = f"You've ordered: {', '.join(items)}. Total cost is ₹{total_cost}."
|
| 43 |
-
else:
|
| 44 |
-
response = "Sorry, I could not find any menu items in your order."
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
gr.Textbox(label="Transcription"),
|
| 64 |
-
gr.Textbox(label="Order Confirmation"),
|
| 65 |
-
gr.Audio(label="TTS Response"),
|
| 66 |
-
],
|
| 67 |
-
title="Voice Ordering System",
|
| 68 |
-
description="Speak your order, and the system will process it.",
|
| 69 |
)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
if __name__ == "__main__":
|
| 72 |
-
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
return f"Command not recognized: {command}"
|
| 3 |
+
|
| 4 |
+
# Define Gradio interfaces
|
| 5 |
+
menu_interface = gr.Interface(
|
| 6 |
+
fn=get_menu,
|
| 7 |
+
inputs=None,
|
| 8 |
+
outputs="json",
|
| 9 |
+
description="Get the menu."
|
| 10 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
order_interface = gr.Interface(
|
| 13 |
+
fn=place_order,
|
| 14 |
+
inputs=["text", "text"],
|
| 15 |
+
outputs="text",
|
| 16 |
+
description="Place an order by providing a comma-separated list of items and customizations."
|
| 17 |
+
)
|
| 18 |
|
| 19 |
+
speak_interface = gr.Interface(
|
| 20 |
+
fn=text_to_speech,
|
| 21 |
+
inputs="text",
|
| 22 |
+
outputs="text",
|
| 23 |
+
description="Convert text to speech."
|
| 24 |
+
)
|
| 25 |
|
| 26 |
+
speech_recognition_interface = gr.Interface(
|
| 27 |
+
fn=live_speech,
|
| 28 |
+
inputs=None,
|
| 29 |
+
outputs="text",
|
| 30 |
+
description="Speak commands like 'Show menu' or 'Order Biryani'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
+
# Combine all interfaces
|
| 34 |
+
app = gr.TabbedInterface([
|
| 35 |
+
menu_interface,
|
| 36 |
+
order_interface,
|
| 37 |
+
speak_interface,
|
| 38 |
+
speech_recognition_interface
|
| 39 |
+
], ["Menu", "Order", "Speak", "Voice Commands"])
|
| 40 |
+
|
| 41 |
if __name__ == "__main__":
|
| 42 |
+
app.launch()
|