Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -13,33 +13,24 @@ pipeline = Pipeline.from_pretrained(
|
|
13 |
use_auth_token=os.environ['api'])
|
14 |
|
15 |
def process_audio(audio):
|
16 |
-
# Extract the audio data and sample rate from the tuple
|
17 |
-
audio_data, sample_rate = audio
|
18 |
-
|
19 |
-
# Ensure the audio data is in the correct format
|
20 |
-
audio_data = np.int16(audio_data / np.max(np.abs(audio_data)) * 32767)
|
21 |
-
|
22 |
-
# Convert audio_data to a numpy array
|
23 |
-
audio_data = np.array(audio_data)
|
24 |
-
|
25 |
# Save the uploaded audio file to a temporary location
|
26 |
-
|
27 |
-
|
|
|
28 |
# Use the diarization pipeline to process the audio
|
29 |
diarization = pipeline("temp.wav")
|
30 |
-
|
31 |
# Remove the temporary file
|
32 |
os.remove("temp.wav")
|
33 |
-
|
34 |
# Return the diarization output
|
35 |
return diarization
|
36 |
|
37 |
with gr.Blocks() as demo:
|
38 |
-
audio_input = gr.Audio(label="Upload Audio")
|
39 |
process_button = gr.Button("Process")
|
40 |
-
diarization_output = gr.
|
41 |
|
42 |
process_button.click(fn=process_audio, inputs=audio_input, outputs=diarization_output)
|
43 |
|
44 |
-
demo.launch()
|
45 |
-
#
|
|
|
13 |
use_auth_token=os.environ['api'])
|
14 |
|
15 |
def process_audio(audio):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Save the uploaded audio file to a temporary location
|
17 |
+
with open("temp.wav", "wb") as f:
|
18 |
+
f.write(audio)
|
19 |
+
|
20 |
# Use the diarization pipeline to process the audio
|
21 |
diarization = pipeline("temp.wav")
|
22 |
+
|
23 |
# Remove the temporary file
|
24 |
os.remove("temp.wav")
|
25 |
+
|
26 |
# Return the diarization output
|
27 |
return diarization
|
28 |
|
29 |
with gr.Blocks() as demo:
|
30 |
+
audio_input = gr.Audio(type="file", label="Upload Audio")
|
31 |
process_button = gr.Button("Process")
|
32 |
+
diarization_output = gr.Textbox(label="Diarization Output")
|
33 |
|
34 |
process_button.click(fn=process_audio, inputs=audio_input, outputs=diarization_output)
|
35 |
|
36 |
+
demo.launch()
|
|