File size: 2,390 Bytes
2b54f3f
 
 
4c3594b
743d607
 
2b54f3f
4c3594b
2b54f3f
 
 
 
 
 
743d607
2b54f3f
743d607
 
 
 
 
329c61b
 
 
 
 
 
 
 
 
 
 
 
 
 
2b54f3f
743d607
2b54f3f
743d607
2b54f3f
 
743d607
2b54f3f
 
 
 
 
 
 
 
743d607
2b54f3f
 
329c61b
743d607
2b54f3f
329c61b
 
2b54f3f
329c61b
2b54f3f
743d607
 
2b54f3f
 
743d607
 
2b54f3f
743d607
 
2b54f3f
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
from transformers import pipeline
import subprocess
import os
import pyttsx3
import shutil

# === TEXT SCRIPT GENERATOR ===
generator = pipeline("text-generation", model="gpt2")

def generate_script(prompt):
    result = generator(f"Scene: {prompt}\nDescription:", max_length=80, num_return_sequences=1)
    return result[0]["generated_text"]

# === VOICE GENERATOR using pyttsx3 (Fast + CPU Friendly)
def generate_voice(script):
    engine = pyttsx3.init()
    engine.setProperty('rate', 150)
    engine.save_to_file(script, 'voice.wav')
    engine.runAndWait()
    return "voice.wav"

# === BACKGROUND MUSIC MIXER ===
def merge_voice_and_music(voice_path, music_path, output_path="final_audio.wav"):
    command = [
        "ffmpeg", "-y",
        "-i", voice_path,
        "-i", music_path,
        "-filter_complex", "[1:0]volume=0.3[a1];[0:0][a1]amix=inputs=2:duration=shortest",
        "-c:a", "aac",
        "-shortest",
        output_path
    ]
    subprocess.call(command)
    return output_path

# === DUMMY VIDEO GENERATOR (use uploaded sample)
def generate_video(prompt):
    shutil.copyfile("sample.mp4", "modelscope_output.mp4")
    return "modelscope_output.mp4"

# === MERGE AUDIO + VIDEO ===
def merge_audio_video(audio_path, video_path):
    output = "final_output.mp4"
    subprocess.call([
        "ffmpeg", "-y", "-i", video_path, "-i", audio_path,
        "-c:v", "copy", "-c:a", "aac", "-shortest", output
    ])
    return output

# === FULL PIPELINE ===
def full_pipeline(prompt):
    script = generate_script(prompt)
    voice = generate_voice(script)
    final_audio = merge_voice_and_music(voice, "bg_music.mp3")
    video = generate_video(prompt)
    final_video = merge_audio_video(final_audio, video)
    return final_video, script

# === UI ===
with gr.Blocks() as demo:
    gr.Markdown("# 🎬 Free AI Reels Generator (CPU Only Version)")
    gr.Markdown("Script + Voice + Music + Video on 100% free CPU tier")

    with gr.Row():
        input_prompt = gr.Textbox(label="🎀 Scene Prompt", placeholder="e.g. A monk in the Himalayas walking through mist")
        generate_btn = gr.Button("Generate Reel")

    output_video = gr.Video(label="🎞️ Final Output")
    output_script = gr.Textbox(label="πŸ“ Script")

    generate_btn.click(fn=full_pipeline, inputs=input_prompt, outputs=[output_video, output_script])

demo.launch()