arkay22 commited on
Commit
1821112
·
verified ·
1 Parent(s): 97b4f2d

New file creation

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import transformers
3
+ import librosa
4
+ import numpy as np
5
+
6
+ # Load the model pipeline
7
+ pipe = transformers.pipeline(
8
+ model='fixie-ai/ultravox-v0_5-llama-3_1-8b',
9
+ trust_remote_code=True
10
+ )
11
+
12
+ def transcribe(audio):
13
+ if audio is None:
14
+ return "No audio provided."
15
+
16
+ # Load audio using librosa
17
+ audio_array, sr = librosa.load(audio, sr=16000)
18
+
19
+ # Define initial system prompt
20
+ turns = [
21
+ {
22
+ "role": "system",
23
+ "content": "You are a friendly and helpful character. You love to answer questions for people."
24
+ },
25
+ ]
26
+
27
+ # Run inference
28
+ result = pipe(
29
+ {'audio': audio_array, 'turns': turns, 'sampling_rate': sr},
30
+ max_new_tokens=30
31
+ )
32
+
33
+ # Return result content
34
+ return result[0]['content'] if isinstance(result, list) else str(result)
35
+
36
+ # Build Gradio Interface
37
+ demo = gr.Interface(
38
+ fn=transcribe,
39
+ inputs=gr.Audio(source="upload", type="filepath", label="Upload an Audio File"),
40
+ outputs=gr.Textbox(label="Ultravox Response"),
41
+ title="🎙️ Ultravox AI Voicebot",
42
+ description="Upload an audio file and Ultravox will respond intelligently!"
43
+ )
44
+
45
+ # Launch app
46
+ if __name__ == "__main__":
47
+ demo.launch()