Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import subprocess
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# === TEXT SCRIPT GENERATOR ===
|
| 7 |
generator = pipeline("text-generation", model="gpt2")
|
|
@@ -10,12 +12,13 @@ def generate_script(prompt):
|
|
| 10 |
result = generator(f"Scene: {prompt}\nDescription:", max_length=80, num_return_sequences=1)
|
| 11 |
return result[0]["generated_text"]
|
| 12 |
|
| 13 |
-
# === VOICE GENERATOR (
|
| 14 |
def generate_voice(script):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
# === BACKGROUND MUSIC MIXER ===
|
| 21 |
def merge_voice_and_music(voice_path, music_path, output_path="final_audio.wav"):
|
|
@@ -31,12 +34,12 @@ def merge_voice_and_music(voice_path, music_path, output_path="final_audio.wav")
|
|
| 31 |
subprocess.call(command)
|
| 32 |
return output_path
|
| 33 |
|
| 34 |
-
# === VIDEO GENERATOR
|
| 35 |
def generate_video(prompt):
|
| 36 |
-
|
| 37 |
return "modelscope_output.mp4"
|
| 38 |
|
| 39 |
-
# ===
|
| 40 |
def merge_audio_video(audio_path, video_path):
|
| 41 |
output = "final_output.mp4"
|
| 42 |
subprocess.call([
|
|
@@ -45,26 +48,26 @@ def merge_audio_video(audio_path, video_path):
|
|
| 45 |
])
|
| 46 |
return output
|
| 47 |
|
| 48 |
-
# === PIPELINE ===
|
| 49 |
def full_pipeline(prompt):
|
| 50 |
script = generate_script(prompt)
|
| 51 |
voice = generate_voice(script)
|
| 52 |
-
final_audio = merge_voice_and_music(voice, "bg_music.mp3")
|
| 53 |
video = generate_video(prompt)
|
| 54 |
final_video = merge_audio_video(final_audio, video)
|
| 55 |
return final_video, script
|
| 56 |
|
| 57 |
# === UI ===
|
| 58 |
with gr.Blocks() as demo:
|
| 59 |
-
gr.Markdown("# π¬ Free
|
| 60 |
-
gr.Markdown("
|
| 61 |
|
| 62 |
with gr.Row():
|
| 63 |
-
input_prompt = gr.Textbox(label="π€ Scene Prompt", placeholder="e.g. A monk
|
| 64 |
-
generate_btn = gr.Button("
|
| 65 |
|
| 66 |
-
output_video = gr.Video(label="
|
| 67 |
-
output_script = gr.Textbox(label="π
|
| 68 |
|
| 69 |
generate_btn.click(fn=full_pipeline, inputs=input_prompt, outputs=[output_video, output_script])
|
| 70 |
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import subprocess
|
| 4 |
import os
|
| 5 |
+
import pyttsx3
|
| 6 |
+
import shutil
|
| 7 |
|
| 8 |
# === TEXT SCRIPT GENERATOR ===
|
| 9 |
generator = pipeline("text-generation", model="gpt2")
|
|
|
|
| 12 |
result = generator(f"Scene: {prompt}\nDescription:", max_length=80, num_return_sequences=1)
|
| 13 |
return result[0]["generated_text"]
|
| 14 |
|
| 15 |
+
# === VOICE GENERATOR using pyttsx3 (Fast + CPU Friendly)
|
| 16 |
def generate_voice(script):
|
| 17 |
+
engine = pyttsx3.init()
|
| 18 |
+
engine.setProperty('rate', 150)
|
| 19 |
+
engine.save_to_file(script, 'voice.wav')
|
| 20 |
+
engine.runAndWait()
|
| 21 |
+
return "voice.wav"
|
| 22 |
|
| 23 |
# === BACKGROUND MUSIC MIXER ===
|
| 24 |
def merge_voice_and_music(voice_path, music_path, output_path="final_audio.wav"):
|
|
|
|
| 34 |
subprocess.call(command)
|
| 35 |
return output_path
|
| 36 |
|
| 37 |
+
# === DUMMY VIDEO GENERATOR (use uploaded sample)
|
| 38 |
def generate_video(prompt):
|
| 39 |
+
shutil.copyfile("sample.mp4", "modelscope_output.mp4")
|
| 40 |
return "modelscope_output.mp4"
|
| 41 |
|
| 42 |
+
# === MERGE AUDIO + VIDEO ===
|
| 43 |
def merge_audio_video(audio_path, video_path):
|
| 44 |
output = "final_output.mp4"
|
| 45 |
subprocess.call([
|
|
|
|
| 48 |
])
|
| 49 |
return output
|
| 50 |
|
| 51 |
+
# === FULL PIPELINE ===
|
| 52 |
def full_pipeline(prompt):
|
| 53 |
script = generate_script(prompt)
|
| 54 |
voice = generate_voice(script)
|
| 55 |
+
final_audio = merge_voice_and_music(voice, "bg_music.mp3")
|
| 56 |
video = generate_video(prompt)
|
| 57 |
final_video = merge_audio_video(final_audio, video)
|
| 58 |
return final_video, script
|
| 59 |
|
| 60 |
# === UI ===
|
| 61 |
with gr.Blocks() as demo:
|
| 62 |
+
gr.Markdown("# π¬ Free AI Reels Generator (CPU Only Version)")
|
| 63 |
+
gr.Markdown("Script + Voice + Music + Video on 100% free CPU tier")
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
+
input_prompt = gr.Textbox(label="π€ Scene Prompt", placeholder="e.g. A monk in the Himalayas walking through mist")
|
| 67 |
+
generate_btn = gr.Button("Generate Reel")
|
| 68 |
|
| 69 |
+
output_video = gr.Video(label="ποΈ Final Output")
|
| 70 |
+
output_script = gr.Textbox(label="π Script")
|
| 71 |
|
| 72 |
generate_btn.click(fn=full_pipeline, inputs=input_prompt, outputs=[output_video, output_script])
|
| 73 |
|