File size: 1,222 Bytes
1821112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
import transformers
import librosa
import numpy as np

# Load the model pipeline
pipe = transformers.pipeline(
    model='fixie-ai/ultravox-v0_5-llama-3_1-8b',
    trust_remote_code=True
)

def transcribe(audio):
    if audio is None:
        return "No audio provided."

    # Load audio using librosa
    audio_array, sr = librosa.load(audio, sr=16000)

    # Define initial system prompt
    turns = [
        {
            "role": "system",
            "content": "You are a friendly and helpful character. You love to answer questions for people."
        },
    ]

    # Run inference
    result = pipe(
        {'audio': audio_array, 'turns': turns, 'sampling_rate': sr},
        max_new_tokens=30
    )

    # Return result content
    return result[0]['content'] if isinstance(result, list) else str(result)

# Build Gradio Interface
demo = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(source="upload", type="filepath", label="Upload an Audio File"),
    outputs=gr.Textbox(label="Ultravox Response"),
    title="๐ŸŽ™๏ธ Ultravox AI Voicebot",
    description="Upload an audio file and Ultravox will respond intelligently!"
)

# Launch app
if __name__ == "__main__":
    demo.launch()