Spaces:
Running
Running
KanvaBhatia
commited on
Commit
•
68647bf
1
Parent(s):
89e1e33
Update app.py
Browse files
app.py
CHANGED
@@ -31,11 +31,15 @@ model = torch.load(("model.pth"), map_location=torch.device('cpu'))
|
|
31 |
model.to(DEVICE)
|
32 |
model.eval()
|
33 |
|
34 |
-
def identity(
|
35 |
-
print(
|
36 |
# audio = mp.AudioFileClip(x)
|
37 |
-
wav_file = x
|
38 |
# audio.write_audiofile(wav_file)
|
|
|
|
|
|
|
|
|
39 |
print("Wav stored.")
|
40 |
meta = AudioMetaData(-1, -1, -1, -1, "")
|
41 |
sr = config("sr", 48000, int, section="df")
|
@@ -63,13 +67,22 @@ def identity(x):
|
|
63 |
enhanced = torch.cat(estimate, dim = -1)
|
64 |
sr = meta.sample_rate
|
65 |
save_audio("enhanced_aud.wav", enhanced, sr)
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
demo = gr.Interface(
|
69 |
fn=identity,
|
70 |
title="Audio Denoiser using DeepFilterNet V3",
|
71 |
description="Implemented audio denoising using DeepFilterNet V3, enabled processing of larger files even on cpu, by splitting up the audio file into chunks of 1 minute each.\n\nThe processing will be very slow since it's the free version of HuggingFace, 2 second audio can take about 5 minutes.",
|
72 |
-
|
73 |
-
outputs=gr.
|
74 |
)
|
75 |
demo.launch()
|
|
|
31 |
model.to(DEVICE)
|
32 |
model.eval()
|
33 |
|
34 |
+
def identity(video_path):
|
35 |
+
print(video_path)
|
36 |
# audio = mp.AudioFileClip(x)
|
37 |
+
# wav_file = x
|
38 |
# audio.write_audiofile(wav_file)
|
39 |
+
video = mp.VideoFileClip(video_path)
|
40 |
+
audio = video.audio
|
41 |
+
wav_file = "tmp.wav"
|
42 |
+
audio.write_audiofile(wav_file)
|
43 |
print("Wav stored.")
|
44 |
meta = AudioMetaData(-1, -1, -1, -1, "")
|
45 |
sr = config("sr", 48000, int, section="df")
|
|
|
67 |
enhanced = torch.cat(estimate, dim = -1)
|
68 |
sr = meta.sample_rate
|
69 |
save_audio("enhanced_aud.wav", enhanced, sr)
|
70 |
+
audio = mp.AudioFileClip('enhanced_aud.wav')
|
71 |
+
video = mp.VideoFileClip(video_path)
|
72 |
+
final_video = video.set_audio(audio)
|
73 |
+
final_video.write_videofile("output_video.mp4",
|
74 |
+
codec='libx264',
|
75 |
+
audio_codec='aac',
|
76 |
+
temp_audiofile='temp-audio.m4a',
|
77 |
+
remove_temp=True
|
78 |
+
)
|
79 |
+
return "output_video.mp4"
|
80 |
|
81 |
demo = gr.Interface(
|
82 |
fn=identity,
|
83 |
title="Audio Denoiser using DeepFilterNet V3",
|
84 |
description="Implemented audio denoising using DeepFilterNet V3, enabled processing of larger files even on cpu, by splitting up the audio file into chunks of 1 minute each.\n\nThe processing will be very slow since it's the free version of HuggingFace, 2 second audio can take about 5 minutes.",
|
85 |
+
inputs=gr.Video(label="Input Video", sources="upload"),
|
86 |
+
outputs=gr.Video(label="Output Video"),
|
87 |
)
|
88 |
demo.launch()
|