Spaces:
Runtime error
Runtime error
| # app.py | |
| import os | |
| import gradio as gr | |
| from transformers import pipeline | |
| hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN") # this is None if not set | |
| # 1. Speech-to-text (Whisper small) | |
| asr = pipeline("automatic-speech-recognition", model="openai/whisper-small") | |
| # 2. Text generation (LLM) | |
| chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.2", use_auth_token=hf_token) | |
| # 3. Text-to-speech (Parler-TTS mini) | |
| tts = pipeline("text-to-speech", model="parler-tts/parler-tts-mini-multilingual") | |
| def voice_interview(audio): | |
| # audio is a (sample_rate, numpy array) | |
| transcript = asr(audio)["text"] | |
| reply = chatbot(transcript, max_length=200, do_sample=True)[0]["generated_text"] | |
| audio_out = tts(reply) # returns dict with 'audio' key | |
| return transcript, reply, (audio_out["audio"], audio_out["sampling_rate"]) | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### 🎤 Mock Interview Bot") | |
| audio_in = gr.Audio(sources=["microphone"], type="numpy", label="Speak your answer") | |
| transcript_out = gr.Textbox(label="Transcript") | |
| reply_out = gr.Textbox(label="Bot Reply") | |
| audio_out = gr.Audio(label="Bot's Voice Reply") | |
| btn = gr.Button("Submit") | |
| btn.click(fn=voice_interview, inputs=audio_in, outputs=[transcript_out, reply_out, audio_out]) | |
| demo.launch() |