Update predict.py
Browse files- predict.py +13 -16
predict.py
CHANGED
@@ -2,6 +2,15 @@ import subprocess
|
|
2 |
import gradio as gr
|
3 |
import tempfile
|
4 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
class Predictor:
|
7 |
def predict(self,
|
@@ -30,21 +39,21 @@ class Predictor:
|
|
30 |
background_image_path = tempfile.mktemp(suffix=".png")
|
31 |
final_video_path = tempfile.mktemp(suffix=".mp4")
|
32 |
|
33 |
-
|
34 |
subprocess.run([
|
35 |
'ffmpeg', '-y', '-i', waveform_video, '-vf',
|
36 |
f'pad=width=1000:height=667:x=0:y=467:color={bg_color[1:]}',
|
37 |
padded_waveform_path
|
38 |
], check=True)
|
39 |
|
40 |
-
|
41 |
subprocess.run([
|
42 |
'convert', '-background', bg_color, '-fill', bars_color, '-font', '/src/fonts/Roboto-Black.ttf',
|
43 |
'-pointsize', '48', '-size', '900x367', '-gravity', 'center', f'caption:{caption_text}',
|
44 |
'-bordercolor', bg_color, '-border', '40', background_image_path
|
45 |
], check=True)
|
46 |
|
47 |
-
|
48 |
subprocess.run([
|
49 |
'ffmpeg', '-y', '-i', padded_waveform_path, '-i', background_image_path,
|
50 |
'-filter_complex', 'overlay=0:0', final_video_path
|
@@ -71,16 +80,4 @@ interface = gr.Interface(
|
|
71 |
fn=gradio_predict,
|
72 |
inputs=[
|
73 |
gr.Audio(source="upload", type="filepath", label="Audio File"),
|
74 |
-
gr.Textbox(value="#
|
75 |
-
gr.Slider(0, 1, value=0.75, label="Foreground Opacity"),
|
76 |
-
gr.ColorPicker(value="#ffffff", label="Bars Color"),
|
77 |
-
gr.Slider(10, 500, value=100, step=1, label="Number of Bars"),
|
78 |
-
gr.Slider(0, 1, value=0.4, step=0.1, label="Bar Width"),
|
79 |
-
gr.Textbox(value="", label="Caption Text")
|
80 |
-
],
|
81 |
-
outputs=gr.Video(label="Waveform Video"),
|
82 |
-
live=False
|
83 |
-
)
|
84 |
-
|
85 |
-
if __name__ == "__main__":
|
86 |
-
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
2 |
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...")
|
9 |
+
for path in ['/tmp', '/usr/share/fonts', '/root/.config', '/src/fonts', '/src/flagged']:
|
10 |
+
if os.access(path, os.W_OK):
|
11 |
+
print(f'Directory {path} is writable.')
|
12 |
+
else:
|
13 |
+
print(f'Error: Directory {path} is not writable.')
|
14 |
|
15 |
class Predictor:
|
16 |
def predict(self,
|
|
|
39 |
background_image_path = tempfile.mktemp(suffix=".png")
|
40 |
final_video_path = tempfile.mktemp(suffix=".mp4")
|
41 |
|
42 |
+
print("Running ffmpeg to add padding...")
|
43 |
subprocess.run([
|
44 |
'ffmpeg', '-y', '-i', waveform_video, '-vf',
|
45 |
f'pad=width=1000:height=667:x=0:y=467:color={bg_color[1:]}',
|
46 |
padded_waveform_path
|
47 |
], check=True)
|
48 |
|
49 |
+
print("Creating an image using ImageMagick...")
|
50 |
subprocess.run([
|
51 |
'convert', '-background', bg_color, '-fill', bars_color, '-font', '/src/fonts/Roboto-Black.ttf',
|
52 |
'-pointsize', '48', '-size', '900x367', '-gravity', 'center', f'caption:{caption_text}',
|
53 |
'-bordercolor', bg_color, '-border', '40', background_image_path
|
54 |
], check=True)
|
55 |
|
56 |
+
print("Overlaying the image on the padded waveform video...")
|
57 |
subprocess.run([
|
58 |
'ffmpeg', '-y', '-i', padded_waveform_path, '-i', background_image_path,
|
59 |
'-filter_complex', 'overlay=0:0', final_video_path
|
|
|
80 |
fn=gradio_predict,
|
81 |
inputs=[
|
82 |
gr.Audio(source="upload", type="filepath", label="Audio File"),
|
83 |
+
gr.Textbox(value="#000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|