File size: 1,064 Bytes
4c3d026
 
 
25d1ea3
 
 
4c3d026
 
25d1ea3
 
 
 
 
 
 
 
 
 
4c3d026
25d1ea3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr

with gr.Blocks() as demo:
    model_choice = gr.Dropdown(["openai/whisper-large", "HuggingFaceH4/zephyr-7b-beta"], 
                                label="Choose Model", value="openai/whisper-large")
    input_data = gr.Audio(source="microphone", type="filepath", label="Speak Your Message")  # Note: type is now "filepath"
    output_text = gr.Textbox(label="Transcription and Response")

    def generate_response(audio_path, model_name):
        hf_interface = gr.Interface.load(model_name)  # Load the model directly from the Hub
        if model_name == "openai/whisper-large":
            transcription = hf_interface(audio_path)  # Handle transcription
        else:  # Zephyr
            transcription = hf_interface(audio_path)[0]["generated_text"] # Extract transcription from zephyr
        response = hf_interface(transcription)[0]["generated_text"]  # Get Zephyr's response 
        return transcription, response
    
    input_data.change(generate_response, inputs=[input_data, model_choice], outputs=output_text)

demo.launch()