File size: 869 Bytes
02164cf
 
 
5bf914c
cd16ab7
5bf914c
cd16ab7
 
 
 
 
02164cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
import transformers
import librosa
import os
import soundfile as sf

pipe = transformers.pipeline(
    model='fixie-ai/ultravox-v0_5-llama-3_1-8b',
    trust_remote_code=True,
    use_auth_token=os.getenv("HF_TOKEN")  # relies on Secrets -> HF_TOKEN
)
def chat_with_voice(audio_file):
    audio, sr = librosa.load(audio_file, sr=16000)
    turns = [
        {
            "role": "system",
            "content": "You are a friendly and helpful character. You love to answer questions for people."
        },
    ]
    output = pipe({'audio': audio, 'turns': turns, 'sampling_rate': sr}, max_new_tokens=30)
    return output[0]['content']
demo = gr.Interface(fn=chat_with_voice,
                    inputs=gr.Audio(source="upload", type="filepath"),
                    outputs="text",
                    title="Ultravox Voice Chat")
demo.launch()