Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
|
4 |
+
# Create pipelines for ASR, QA, and TTS
|
5 |
+
asr_pipeline = pipeline("automatic-speech-recognition", model="canary/asr-small-librispeech", device=0) # Adjust device based on your hardware
|
6 |
+
qa_pipeline = pipeline("question-answering", model="LLAMA/llama3-base-qa", tokenizer="LLAMA/llama3-base-qa")
|
7 |
+
tts_pipeline = pipeline("text-to-speech", model="patrickvonplaten/vits-large", device=0) # Adjust device based on your hardware
|
8 |
+
|
9 |
+
def ai_assistant(audio_input):
|
10 |
+
# Perform automatic speech recognition (ASR)
|
11 |
+
transcribed_text = asr_pipeline(audio_input)[0]['transcription']
|
12 |
+
|
13 |
+
# Perform question answering (QA)
|
14 |
+
question = transcribed_text
|
15 |
+
context = "Insert your context here" # Provide the context for the question answering model
|
16 |
+
answer = qa_pipeline(question=question, context=context)
|
17 |
+
|
18 |
+
# Convert the answer to speech using text-to-speech (TTS)
|
19 |
+
tts_output = tts_pipeline(answer['answer'])
|
20 |
+
|
21 |
+
# Output the speech
|
22 |
+
return tts_output[0]['audio']
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
# Create a Gradio interface
|
26 |
+
gr.Interface(ai_assistant,
|
27 |
+
inputs=gr.inputs.Audio(source="microphone", type="microphone", label="Speak Here"),
|
28 |
+
outputs=gr.outputs.Audio(type="audio", label="Assistant's Response"),
|
29 |
+
title="AI Assistant",
|
30 |
+
description="An AI Assistant that answers questions based on your speech input.")
|
31 |
+
.launch()
|