Subbu1304 commited on
Commit
f3be9dc
·
verified ·
1 Parent(s): 56cbacb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -65
app.py CHANGED
@@ -1,72 +1,42 @@
1
  import gradio as gr
2
- from gtts import gTTS
3
- from transformers import pipeline
4
- import whisper
5
- import os
6
-
7
- # Initialize Whisper Model
8
- model = whisper.load_model("base")
9
-
10
- # Load NLP Model
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
- # Generate TTS Audio
47
- tts = gTTS(text=response, lang="en")
48
- audio_path = "response.mp3"
49
- tts.save(audio_path)
50
- return response, audio_path
 
51
 
52
- # Gradio Interface
53
- def order_from_audio(audio):
54
- transcription = speech_to_text(audio)
55
- response, audio_path = process_order(transcription)
56
- return transcription, response, audio_path
 
57
 
58
- # Gradio UI
59
- app = gr.Interface(
60
- fn=order_from_audio,
61
- inputs=gr.Audio(source="microphone", type="filepath"),
62
- outputs=[
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()