Spaces:
Running
Running
Commit
·
bf065fa
1
Parent(s):
ba7a7b5
add moviepy and video 2 audio conversion
Browse files- Dockerfile +1 -1
- app.py +55 -19
Dockerfile
CHANGED
@@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y \
|
|
9 |
&& rm -rf /var/lib/apt/lists/*
|
10 |
|
11 |
# Install pip packages
|
12 |
-
RUN pip install gradio==3.50.2
|
13 |
|
14 |
# Set environment variables for matplotlib and fontconfig
|
15 |
ENV MPLCONFIGDIR=/tmp/matplotlib
|
|
|
9 |
&& rm -rf /var/lib/apt/lists/*
|
10 |
|
11 |
# Install pip packages
|
12 |
+
RUN pip install gradio==3.50.2 moviepy==1.0.3
|
13 |
|
14 |
# Set environment variables for matplotlib and fontconfig
|
15 |
ENV MPLCONFIGDIR=/tmp/matplotlib
|
app.py
CHANGED
@@ -3,6 +3,17 @@ import gradio as gr
|
|
3 |
import tempfile
|
4 |
from pathlib import Path
|
5 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Check permissions and environment setup
|
8 |
print("Checking directory and file permissions...")
|
@@ -62,8 +73,12 @@ class Predictor:
|
|
62 |
return final_video_path
|
63 |
|
64 |
# Gradio user interface
|
65 |
-
def gradio_predict(
|
66 |
predictor = Predictor()
|
|
|
|
|
|
|
|
|
67 |
result = predictor.predict(
|
68 |
audio=audio,
|
69 |
bg_color=bg_color,
|
@@ -75,23 +90,44 @@ def gradio_predict(audio, bg_color, fg_alpha, bars_color, bar_count, bar_width,
|
|
75 |
)
|
76 |
return result
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
if __name__ == "__main__":
|
96 |
-
|
97 |
-
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
3 |
import tempfile
|
4 |
from pathlib import Path
|
5 |
import os
|
6 |
+
from moviepy.editor import VideoFileClip
|
7 |
+
|
8 |
+
def convert_video_to_audio(video_input):
|
9 |
+
video_clip = VideoFileClip(video_input)
|
10 |
+
audio_clip = video_clip.audio
|
11 |
+
audio_clip_filepath = os.path.normpath(f"{video_input.split('.')[0]}.m4a")
|
12 |
+
audio_clip.write_audiofile(audio_clip_filepath, codec='aac')
|
13 |
+
audio_clip.close()
|
14 |
+
video_clip.close()
|
15 |
+
return audio_clip_filepath
|
16 |
+
|
17 |
|
18 |
# Check permissions and environment setup
|
19 |
print("Checking directory and file permissions...")
|
|
|
73 |
return final_video_path
|
74 |
|
75 |
# Gradio user interface
|
76 |
+
def gradio_predict(input_obj, input_obj_type, bg_color, fg_alpha, bars_color, bar_count, bar_width, caption_text):
|
77 |
predictor = Predictor()
|
78 |
+
if input_obj_type =="video":
|
79 |
+
audio = convert_video_to_audio(video_input=input_obj)
|
80 |
+
else:
|
81 |
+
audio = input_obj
|
82 |
result = predictor.predict(
|
83 |
audio=audio,
|
84 |
bg_color=bg_color,
|
|
|
90 |
)
|
91 |
return result
|
92 |
|
93 |
+
def main():
|
94 |
+
with gr.Blocks(title="Speech Enhancement", delete_cache=(86400, 86400), theme=gr.themes.Ocean()) as demo:
|
95 |
+
with gr.Tabs(selected="video") as tabs:
|
96 |
+
with gr.Tab("Video", id="video"):
|
97 |
+
gr.Interface(
|
98 |
+
fn=gradio_predict,
|
99 |
+
inputs=[
|
100 |
+
gr.Video(source="upload", label="Video File"),
|
101 |
+
gr.Radio(choices=["video"], value="video", label="File Type"),
|
102 |
+
gr.Textbox(value="#000000", label="Background Color"),
|
103 |
+
gr.Slider(0, 1, value=0.75, label="Foreground Opacity"),
|
104 |
+
gr.ColorPicker(value="#ffffff", label="Bars Color"),
|
105 |
+
gr.Slider(10, 500, value=100, step=1, label="Number of Bars"),
|
106 |
+
gr.Slider(0, 1, value=0.4, step=0.1, label="Bar Width"),
|
107 |
+
gr.Textbox(value="", label="Caption Text")
|
108 |
+
],
|
109 |
+
outputs=gr.Video(label="Waveform Video"),
|
110 |
+
live=False,
|
111 |
+
allow_flagging="never"
|
112 |
+
)
|
113 |
+
with gr.Tab("Audio", id="audio"):
|
114 |
+
gr.Interface(
|
115 |
+
fn=gradio_predict,
|
116 |
+
inputs=[
|
117 |
+
gr.Audio(source="upload", type="filepath", label="Audio File"),
|
118 |
+
gr.Radio(choices=["audio"], value="audio", label="File Type"),
|
119 |
+
gr.Textbox(value="#000000", label="Background Color"),
|
120 |
+
gr.Slider(0, 1, value=0.75, label="Foreground Opacity"),
|
121 |
+
gr.ColorPicker(value="#ffffff", label="Bars Color"),
|
122 |
+
gr.Slider(10, 500, value=100, step=1, label="Number of Bars"),
|
123 |
+
gr.Slider(0, 1, value=0.4, step=0.1, label="Bar Width"),
|
124 |
+
gr.Textbox(value="", label="Caption Text")
|
125 |
+
],
|
126 |
+
outputs=gr.Video(label="Waveform Video"),
|
127 |
+
live=False,
|
128 |
+
allow_flagging="never"
|
129 |
+
)
|
130 |
+
demo.launch()
|
131 |
|
132 |
if __name__ == "__main__":
|
133 |
+
main()
|
|