Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,38 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
-
# --- Sicherstellen, dass MoviePy
|
| 5 |
os.system(f"{sys.executable} -m pip install --upgrade moviepy imageio-ffmpeg ffmpeg-python")
|
| 6 |
|
| 7 |
-
# --- Import nach Installation ---
|
| 8 |
from moviepy.editor import ImageClip, AudioFileClip, concatenate_videoclips
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
#
|
| 14 |
-
images = ["frame1.png", "frame2.png", "frame3.png"]
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
return "Audio-Datei fehlt. Bitte zuerst generieren."
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
# Video speichern
|
| 34 |
output_path = "output.mp4"
|
|
@@ -39,10 +43,13 @@ def generate_video():
|
|
| 39 |
# --- Gradio Interface ---
|
| 40 |
iface = gr.Interface(
|
| 41 |
fn=generate_video,
|
| 42 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
| 43 |
outputs=gr.File(label="Download Video"),
|
| 44 |
title="Faceless AI Video Generator",
|
| 45 |
-
description="
|
| 46 |
)
|
| 47 |
|
| 48 |
iface.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
+
# --- Sicherstellen, dass MoviePy installiert ist ---
|
| 5 |
os.system(f"{sys.executable} -m pip install --upgrade moviepy imageio-ffmpeg ffmpeg-python")
|
| 6 |
|
|
|
|
| 7 |
from moviepy.editor import ImageClip, AudioFileClip, concatenate_videoclips
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
+
def generate_video(images, audio):
|
| 11 |
+
# images: Liste von hochgeladenen Bild-Dateien
|
| 12 |
+
# audio: hochgeladene Audio-Datei
|
|
|
|
| 13 |
|
| 14 |
+
if len(images) == 0:
|
| 15 |
+
return "Bitte mindestens ein Bild hochladen."
|
| 16 |
+
if audio is None:
|
| 17 |
+
return "Bitte eine Audio-Datei hochladen."
|
| 18 |
|
| 19 |
+
# Temporäre Pfade speichern
|
| 20 |
+
image_paths = []
|
| 21 |
+
for i, img in enumerate(images):
|
| 22 |
+
path = f"frame_{i}.png"
|
| 23 |
+
img.save(path)
|
| 24 |
+
image_paths.append(path)
|
| 25 |
+
|
| 26 |
+
audio_path = "audio.mp3"
|
| 27 |
+
audio.save(audio_path)
|
| 28 |
|
| 29 |
+
# Video erstellen (jede Bild-Clip 2 Sekunden)
|
| 30 |
+
clips = [ImageClip(img_path).set_duration(2) for img_path in image_paths]
|
| 31 |
+
video = concatenate_videoclips(clips, method="compose")
|
|
|
|
| 32 |
|
| 33 |
+
# Audio einfügen
|
| 34 |
+
audio_clip = AudioFileClip(audio_path)
|
| 35 |
+
video = video.set_audio(audio_clip)
|
| 36 |
|
| 37 |
# Video speichern
|
| 38 |
output_path = "output.mp4"
|
|
|
|
| 43 |
# --- Gradio Interface ---
|
| 44 |
iface = gr.Interface(
|
| 45 |
fn=generate_video,
|
| 46 |
+
inputs=[
|
| 47 |
+
gr.File(file_types=[".png", ".jpg"], file_types_allow_multiple=True, label="Bilder hochladen"),
|
| 48 |
+
gr.File(file_types=[".mp3"], label="Audio hochladen")
|
| 49 |
+
],
|
| 50 |
outputs=gr.File(label="Download Video"),
|
| 51 |
title="Faceless AI Video Generator",
|
| 52 |
+
description="Lade Bilder und eine Audio-Datei hoch, um ein Video zu generieren."
|
| 53 |
)
|
| 54 |
|
| 55 |
iface.launch()
|