Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import os
|
| 4 |
+
import uuid
|
| 5 |
+
|
| 6 |
+
def generate_video(audio, image):
|
| 7 |
+
audio_path = audio.name
|
| 8 |
+
image_path = image.name
|
| 9 |
+
output_filename = f"output_{uuid.uuid4().hex[:8]}.mp4"
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
cmd = [
|
| 13 |
+
"ffmpeg", "-y", "-loop", "1", "-framerate", "1", "-i", image_path,
|
| 14 |
+
"-i", audio_path, "-c:v", "libx264", "-preset", "ultrafast", "-tune", "stillimage",
|
| 15 |
+
"-c:a", "aac", "-b:a", "192k", "-shortest", "-r", "1", "-pix_fmt", "yuv420p", output_filename
|
| 16 |
+
]
|
| 17 |
+
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 18 |
+
|
| 19 |
+
if os.path.exists(output_filename):
|
| 20 |
+
return output_filename
|
| 21 |
+
else:
|
| 22 |
+
return "❌ Something went wrong while generating the video. Please check your files."
|
| 23 |
+
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return f"⚠️ Error: {str(e)}"
|
| 26 |
+
|
| 27 |
+
# UI with minimal theme
|
| 28 |
+
with gr.Blocks(theme="Taithrah/Minimal") as app:
|
| 29 |
+
gr.Markdown("# 🎶 Audio to Video Tool\nUpload an audio file and an image to generate a simple MP4 video (like TunesToTube)")
|
| 30 |
+
with gr.Row():
|
| 31 |
+
audio = gr.Audio(label="🎧 Upload your audio file", type="file")
|
| 32 |
+
image = gr.Image(label="🖼️ Upload your image", type="filepath")
|
| 33 |
+
|
| 34 |
+
submit = gr.Button("🚀 Generate Video")
|
| 35 |
+
output = gr.Video(label="🎬 Your Video")
|
| 36 |
+
|
| 37 |
+
submit.click(fn=generate_video, inputs=[audio, image], outputs=output)
|
| 38 |
+
|
| 39 |
+
app.launch()
|