Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import soundfile as sf
|
3 |
+
from huggingface_hub import hf_hub_download
|
4 |
+
from audiosr.inference import super_resolution
|
5 |
+
import numpy as np
|
6 |
+
import os
|
7 |
+
|
8 |
+
# Download the OpenVINO models
|
9 |
+
hf_hub_download(repo_id="Intel/versatile_audio_super_resolution_openvino", filename="versatile_audio_sr_base_openvino_models.zip", local_dir=".")
|
10 |
+
import zipfile
|
11 |
+
with zipfile.ZipFile("versatile_audio_sr_base_openvino_models.zip", 'r') as zip_ref:
|
12 |
+
zip_ref.extractall(".")
|
13 |
+
|
14 |
+
# Define the model paths
|
15 |
+
model_paths = {
|
16 |
+
'audio_sr_decoder': 'audio_sr_decoder.xml',
|
17 |
+
'audio_sr_encoder': 'audio_sr_encoder.xml',
|
18 |
+
'vae_feature_extract': 'vae_feature_extract.xml',
|
19 |
+
'vocoder': 'vocoder.xml'
|
20 |
+
}
|
21 |
+
|
22 |
+
def audio_super_resolution(audio_file):
|
23 |
+
"""
|
24 |
+
Performs audio super-resolution on the input audio file.
|
25 |
+
"""
|
26 |
+
waveform, sr = sf.read(audio_file)
|
27 |
+
if len(waveform.shape) > 1:
|
28 |
+
waveform = np.mean(waveform, axis=1) # apects mono audio
|
29 |
+
sf.write("input.wav", waveform, sr)
|
30 |
+
|
31 |
+
# Perform super-resolution
|
32 |
+
output = super_resolution(
|
33 |
+
"input.wav",
|
34 |
+
"output.wav",
|
35 |
+
model_paths=model_paths
|
36 |
+
)
|
37 |
+
return "output.wav"
|
38 |
+
|
39 |
+
# Create the Gradio interface
|
40 |
+
iface = gr.Interface(
|
41 |
+
fn=audio_super_resolution,
|
42 |
+
inputs=gr.Audio(type="filepath", label="Input Audio"),
|
43 |
+
outputs=gr.Audio(type="filepath", label="Output Audio"),
|
44 |
+
title="Versatile Audio Super Resolution (OpenVINO)",
|
45 |
+
description="Upload an audio file to perform super-resolution.",
|
46 |
+
examples=[["example.wav"]]
|
47 |
+
)
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
+
iface.launch()
|