geethareddy commited on
Commit
7494646
·
verified ·
1 Parent(s): 29234eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -1,45 +1,46 @@
1
  import gradio as gr
2
  import speech_recognition as sr
 
3
  from transformers import pipeline
4
 
5
- # Initialize the Hugging Face pipeline for speech-to-text
6
- speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-large")
7
-
8
- # Function to process user input (name and email)
9
- def capture_user_info(audio_input):
10
- # Convert speech to text using Hugging Face's ASR model
11
- name = speech_to_text(audio_input)["text"]
12
-
13
- # Now, ask for the email
14
- email_prompt = "Please provide your email address."
15
-
16
- # Return the name and email prompt
17
- return name, email_prompt
18
-
19
- # Function to capture email input after the name
20
- def capture_email(audio_input):
21
- # Convert speech to text for the email
22
- email = speech_to_text(audio_input)["text"]
23
- return email
24
-
25
- # Define Gradio Interface
 
 
 
26
  def gradio_interface():
27
  with gr.Blocks() as demo:
28
- gr.Markdown("### Welcome to Biryani Hub")
29
-
30
  with gr.Column():
31
  gr.Markdown("#### Step 1: Tell me your name")
32
- audio_input_name = gr.Audio(source="microphone", type="filepath", label="Speak your name")
33
  name_output = gr.Textbox(label="Your Name:")
34
-
35
- # Step 1: Capture Name
36
- audio_input_name.change(capture_user_info, inputs=audio_input_name, outputs=[name_output, email_prompt_output])
37
-
38
- gr.Markdown("#### Step 2: Please provide your email address")
39
- audio_input_email = gr.Audio(source="microphone", type="filepath", label="Speak your email")
40
  email_output = gr.Textbox(label="Your Email:")
41
-
42
- # Step 2: Capture Email
43
  audio_input_email.change(capture_email, inputs=audio_input_email, outputs=email_output)
44
 
45
  return demo
 
1
  import gradio as gr
2
  import speech_recognition as sr
3
+ import torch
4
  from transformers import pipeline
5
 
6
+ # Load ASR model (Whisper)
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+ speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=0 if device == "cuda" else -1)
9
+
10
+ # Initialize Speech Recognition
11
+ recognizer = sr.Recognizer()
12
+
13
+ # Function to Capture Name
14
+ def capture_name(audio):
15
+ try:
16
+ text = speech_to_text(audio)["text"]
17
+ return f"Name Captured: {text}", "Please provide your email address."
18
+ except Exception as e:
19
+ return f"Error: {str(e)}", ""
20
+
21
+ # Function to Capture Email
22
+ def capture_email(audio):
23
+ try:
24
+ text = speech_to_text(audio)["text"]
25
+ return f"Email Captured: {text}"
26
+ except Exception as e:
27
+ return f"Error: {str(e)}"
28
+
29
+ # Gradio Interface
30
  def gradio_interface():
31
  with gr.Blocks() as demo:
32
+ gr.Markdown("### 🎙️ Welcome to Biryani Hub")
33
+
34
  with gr.Column():
35
  gr.Markdown("#### Step 1: Tell me your name")
36
+ audio_input_name = gr.Audio(type="filepath", label="Record your Name")
37
  name_output = gr.Textbox(label="Your Name:")
38
+ email_prompt_output = gr.Textbox(label="Next Step:", interactive=False)
39
+ audio_input_name.change(capture_name, inputs=audio_input_name, outputs=[name_output, email_prompt_output])
40
+
41
+ gr.Markdown("#### Step 2: Provide your email")
42
+ audio_input_email = gr.Audio(type="filepath", label="Record your Email")
 
43
  email_output = gr.Textbox(label="Your Email:")
 
 
44
  audio_input_email.change(capture_email, inputs=audio_input_email, outputs=email_output)
45
 
46
  return demo