File size: 1,677 Bytes
2ef525c
83fea8b
 
63d3719
83fea8b
 
2ef525c
 
 
63d3719
 
 
2ef525c
63d3719
 
 
 
2ef525c
63d3719
 
 
 
 
 
 
 
 
2ef525c
63d3719
 
 
2ef525c
63d3719
 
 
2ef525c
 
 
 
 
 
 
83fea8b
2ef525c
 
63d3719
 
 
 
2ef525c
 
63d3719
2ef525c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import sys

# --- Sicherstellen, dass MoviePy installiert ist ---
os.system(f"{sys.executable} -m pip install --upgrade moviepy imageio-ffmpeg ffmpeg-python")

from moviepy.editor import ImageClip, AudioFileClip, concatenate_videoclips
import gradio as gr

def generate_video(images, audio):
    # images: Liste von hochgeladenen Bild-Dateien
    # audio: hochgeladene Audio-Datei
    
    if len(images) == 0:
        return "Bitte mindestens ein Bild hochladen."
    if audio is None:
        return "Bitte eine Audio-Datei hochladen."
    
    # Temporäre Pfade speichern
    image_paths = []
    for i, img in enumerate(images):
        path = f"frame_{i}.png"
        img.save(path)
        image_paths.append(path)
    
    audio_path = "audio.mp3"
    audio.save(audio_path)
    
    # Video erstellen (jede Bild-Clip 2 Sekunden)
    clips = [ImageClip(img_path).set_duration(2) for img_path in image_paths]
    video = concatenate_videoclips(clips, method="compose")
    
    # Audio einfügen
    audio_clip = AudioFileClip(audio_path)
    video = video.set_audio(audio_clip)
    
    # Video speichern
    output_path = "output.mp4"
    video.write_videofile(output_path, fps=24)
    
    return output_path

# --- Gradio Interface ---
iface = gr.Interface(
    fn=generate_video,
    inputs=[
        gr.File(file_types=[".png", ".jpg"], file_types_allow_multiple=True, label="Bilder hochladen"),
        gr.File(file_types=[".mp3"], label="Audio hochladen")
    ],
    outputs=gr.File(label="Download Video"),
    title="Faceless AI Video Generator",
    description="Lade Bilder und eine Audio-Datei hoch, um ein Video zu generieren."
)

iface.launch()