|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
asr_pipeline = pipeline("automatic-speech-recognition", model="canary/asr-small-librispeech", device=0) |
|
qa_pipeline = pipeline("question-answering", model="LLAMA/llama3-base-qa", tokenizer="LLAMA/llama3-base-qa") |
|
tts_pipeline = pipeline("text-to-speech", model="patrickvonplaten/vits-large", device=0) |
|
|
|
def ai_assistant(audio_input): |
|
|
|
transcribed_text = asr_pipeline(audio_input)[0]['transcription'] |
|
|
|
|
|
question = transcribed_text |
|
context = "Insert your context here" |
|
answer = qa_pipeline(question=question, context=context) |
|
|
|
|
|
tts_output = tts_pipeline(answer['answer']) |
|
|
|
|
|
return tts_output[0]['audio'] |
|
|
|
if __name__ == "__main__": |
|
|
|
gr.Interface(ai_assistant, |
|
inputs=gr.inputs.Audio(source="microphone", type="microphone", label="Speak Here"), |
|
outputs=gr.outputs.Audio(type="audio", label="Assistant's Response"), |
|
title="AI Assistant", |
|
description="An AI Assistant that answers questions based on your speech input.") |
|
.launch() |