Subbu1304 commited on
Commit
ba28d5c
·
verified ·
1 Parent(s): a6f23f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -1,14 +1,12 @@
1
  import gradio as gr
2
- import pyttsx3
3
  from transformers import pipeline
4
  import whisper
 
5
 
6
  # Initialize Whisper Model
7
  model = whisper.load_model("base")
8
 
9
- # Initialize Text-to-Speech
10
- engine = pyttsx3.init()
11
-
12
  # Load NLP Model
13
  nlp_pipeline = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
14
 
@@ -30,7 +28,7 @@ def speech_to_text(audio):
30
  except Exception as e:
31
  return f"Error: {str(e)}"
32
 
33
- # NLP Intent Detection
34
  def process_order(transcription):
35
  items = []
36
  total_cost = 0
@@ -45,15 +43,17 @@ def process_order(transcription):
45
  else:
46
  response = "Sorry, I could not find any menu items in your order."
47
 
48
- # Text-to-Speech for Response
49
- engine.say(response)
50
- engine.runAndWait()
51
- return response
 
52
 
53
  # Gradio Interface
54
  def order_from_audio(audio):
55
  transcription = speech_to_text(audio)
56
- return transcription, process_order(transcription)
 
57
 
58
  # Gradio UI
59
  app = gr.Interface(
@@ -62,6 +62,7 @@ app = gr.Interface(
62
  outputs=[
63
  gr.Textbox(label="Transcription"),
64
  gr.Textbox(label="Order Confirmation"),
 
65
  ],
66
  title="Voice Ordering System",
67
  description="Speak your order, and the system will process it.",
 
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
 
 
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
 
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(
 
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.",