import gradio as gr import speech_recognition as sr from transformers import pipeline # Initialize the Hugging Face pipeline for speech-to-text speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-large") # Function to process user input (name and email) def capture_user_info(audio_input): # Convert speech to text using Hugging Face's ASR model name = speech_to_text(audio_input)["text"] # Now, ask for the email email_prompt = "Please provide your email address." # Return the name and email prompt return name, email_prompt # Function to capture email input after the name def capture_email(audio_input): # Convert speech to text for the email email = speech_to_text(audio_input)["text"] return email # Define Gradio Interface def gradio_interface(): with gr.Blocks() as demo: gr.Markdown("### Welcome to Biryani Hub") with gr.Column(): gr.Markdown("#### Step 1: Tell me your name") audio_input_name = gr.Audio(source="microphone", type="filepath", label="Speak your name") name_output = gr.Textbox(label="Your Name:") # Step 1: Capture Name audio_input_name.change(capture_user_info, inputs=audio_input_name, outputs=[name_output, email_prompt_output]) gr.Markdown("#### Step 2: Please provide your email address") audio_input_email = gr.Audio(source="microphone", type="filepath", label="Speak your email") email_output = gr.Textbox(label="Your Email:") # Step 2: Capture Email audio_input_email.change(capture_email, inputs=audio_input_email, outputs=email_output) return demo # Launch the Gradio Interface demo = gradio_interface() demo.launch(debug=True)