Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- README.md +3 -9
- app.py +59 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title: Video
|
| 3 |
-
emoji: 👀
|
| 4 |
-
colorFrom: red
|
| 5 |
-
colorTo: gray
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 5.49.1
|
| 8 |
app_file: app.py
|
| 9 |
-
|
|
|
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Video-Maker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
app_file: app.py
|
| 4 |
+
sdk: gradio
|
| 5 |
+
sdk_version: 5.42.0
|
| 6 |
---
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Gradio “still-image + audio → video” with API
|
| 3 |
+
"""
|
| 4 |
+
import gradio as gr, subprocess, uuid, math, pathlib, shutil, os, tempfile
|
| 5 |
+
|
| 6 |
+
ALLOW_IMG = (".png",".jpg",".jpeg")
|
| 7 |
+
ALLOW_AUD = (".wav",".mp3",".m4a",".flac",".aac")
|
| 8 |
+
|
| 9 |
+
def make_video(image, audio):
|
| 10 |
+
"""
|
| 11 |
+
Gradio wrapper: inputs are file-paths (str) supplied by the component
|
| 12 |
+
Returns: path to generated mp4
|
| 13 |
+
"""
|
| 14 |
+
if not (image and audio):
|
| 15 |
+
raise ValueError("Need both image and audio")
|
| 16 |
+
|
| 17 |
+
uid = uuid.uuid4().hex
|
| 18 |
+
tmpdir = pathlib.Path(tempfile.mkdtemp())
|
| 19 |
+
img_p = tmpdir / f"{uid}_img{pathlib.Path(image).suffix}"
|
| 20 |
+
aud_p = tmpdir / f"{uid}_aud{pathlib.Path(audio).suffix}"
|
| 21 |
+
out_p = tmpdir / f"{uid}.mp4"
|
| 22 |
+
|
| 23 |
+
shutil.copy(image, img_p)
|
| 24 |
+
shutil.copy(audio, aud_p)
|
| 25 |
+
|
| 26 |
+
# audio duration
|
| 27 |
+
probe = subprocess.run(
|
| 28 |
+
["ffprobe","-v","error","-show_entries","format=duration",
|
| 29 |
+
"-of","default=noprint_wrappers=1:nokey=1",str(aud_p)],
|
| 30 |
+
text=True, capture_output=True, check=True)
|
| 31 |
+
dur = math.ceil(float(probe.stdout.strip()))
|
| 32 |
+
|
| 33 |
+
# ffmpeg: still image looped + copy audio
|
| 34 |
+
subprocess.run([
|
| 35 |
+
"ffmpeg","-y","-loop","1","-i",str(img_p),"-i",str(aud_p),
|
| 36 |
+
"-c:v","libx264","-tune","stillimage","-pix_fmt","yuv420p",
|
| 37 |
+
"-c:a","copy","-shortest","-t",str(dur),str(out_p)
|
| 38 |
+
], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 39 |
+
|
| 40 |
+
return str(out_p)
|
| 41 |
+
|
| 42 |
+
# ---------------- Gradio UI ----------------
|
| 43 |
+
with gr.Blocks(title="Image + Audio → Video") as demo:
|
| 44 |
+
gr.Markdown("## Upload an image and an audio file to receive an MP4")
|
| 45 |
+
with gr.Row():
|
| 46 |
+
img_in = gr.Image(type="filepath", label="Image")
|
| 47 |
+
aud_in = gr.Audio(type="filepath", label="Audio")
|
| 48 |
+
btn = gr.Button("Generate video", variant="primary")
|
| 49 |
+
vid_out = gr.Video(label="Result")
|
| 50 |
+
|
| 51 |
+
btn.click(make_video, inputs=[img_in, aud_in], outputs=vid_out)
|
| 52 |
+
|
| 53 |
+
# --------------- API exposure ---------------
|
| 54 |
+
# gradio automatically creates /api/predict that mirrors btn.click
|
| 55 |
+
# We also add an explicit named endpoint so users can discover it
|
| 56 |
+
demo.queue() # required for HF Spaces
|
| 57 |
+
demo.launch(server_name="0.0.0.0",
|
| 58 |
+
server_port=int(os.getenv("PORT", 7860)),
|
| 59 |
+
share=False)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|