Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,19 +10,33 @@ 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 |
with open("input.txt", "w") as f:
|
| 16 |
f.write(script)
|
| 17 |
os.system("python3 bark_infer_cpu.py --text_file input.txt --output bark_output.wav")
|
| 18 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# === VIDEO GENERATOR ===
|
| 21 |
def generate_video(prompt):
|
| 22 |
os.system(f"python3 generate.py --prompt \"{prompt}\" --output modelscope_output.mp4")
|
| 23 |
return "modelscope_output.mp4"
|
| 24 |
|
| 25 |
-
# === MERGE AUDIO + VIDEO ===
|
| 26 |
def merge_audio_video(audio_path, video_path):
|
| 27 |
output = "final_output.mp4"
|
| 28 |
subprocess.call([
|
|
@@ -31,25 +45,26 @@ def merge_audio_video(audio_path, video_path):
|
|
| 31 |
])
|
| 32 |
return output
|
| 33 |
|
| 34 |
-
# ===
|
| 35 |
def full_pipeline(prompt):
|
| 36 |
script = generate_script(prompt)
|
| 37 |
-
|
|
|
|
| 38 |
video = generate_video(prompt)
|
| 39 |
-
|
| 40 |
-
return
|
| 41 |
|
| 42 |
-
# ===
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
-
gr.Markdown("# π¬ Free Veo 3
|
| 45 |
-
gr.Markdown("Enter
|
| 46 |
|
| 47 |
with gr.Row():
|
| 48 |
-
input_prompt = gr.Textbox(label="π€
|
| 49 |
-
generate_btn = gr.Button("ποΈ Generate")
|
| 50 |
|
| 51 |
-
output_video = gr.Video(label="
|
| 52 |
-
output_script = gr.Textbox(label="Generated Script")
|
| 53 |
|
| 54 |
generate_btn.click(fn=full_pipeline, inputs=input_prompt, outputs=[output_video, output_script])
|
| 55 |
|
|
|
|
| 10 |
result = generator(f"Scene: {prompt}\nDescription:", max_length=80, num_return_sequences=1)
|
| 11 |
return result[0]["generated_text"]
|
| 12 |
|
| 13 |
+
# === VOICE GENERATOR (CPU version using Bark) ===
|
| 14 |
def generate_voice(script):
|
| 15 |
with open("input.txt", "w") as f:
|
| 16 |
f.write(script)
|
| 17 |
os.system("python3 bark_infer_cpu.py --text_file input.txt --output bark_output.wav")
|
| 18 |
+
return "bark_output.wav"
|
| 19 |
+
|
| 20 |
+
# === BACKGROUND MUSIC MIXER ===
|
| 21 |
+
def merge_voice_and_music(voice_path, music_path, output_path="final_audio.wav"):
|
| 22 |
+
command = [
|
| 23 |
+
"ffmpeg", "-y",
|
| 24 |
+
"-i", voice_path,
|
| 25 |
+
"-i", music_path,
|
| 26 |
+
"-filter_complex", "[1:0]volume=0.3[a1];[0:0][a1]amix=inputs=2:duration=shortest",
|
| 27 |
+
"-c:a", "aac",
|
| 28 |
+
"-shortest",
|
| 29 |
+
output_path
|
| 30 |
+
]
|
| 31 |
+
subprocess.call(command)
|
| 32 |
+
return output_path
|
| 33 |
|
| 34 |
# === VIDEO GENERATOR ===
|
| 35 |
def generate_video(prompt):
|
| 36 |
os.system(f"python3 generate.py --prompt \"{prompt}\" --output modelscope_output.mp4")
|
| 37 |
return "modelscope_output.mp4"
|
| 38 |
|
| 39 |
+
# === FINAL MERGE: AUDIO + VIDEO ===
|
| 40 |
def merge_audio_video(audio_path, video_path):
|
| 41 |
output = "final_output.mp4"
|
| 42 |
subprocess.call([
|
|
|
|
| 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") # Replace with your background music file
|
| 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 Veo 3 Style AI Video Generator (with Background Music)")
|
| 60 |
+
gr.Markdown("Enter your scene. Get AI script + voice + music + video.")
|
| 61 |
|
| 62 |
with gr.Row():
|
| 63 |
+
input_prompt = gr.Textbox(label="π€ Scene Prompt", placeholder="e.g. A monk walking through glowing forest in rain")
|
| 64 |
+
generate_btn = gr.Button("ποΈ Generate Video")
|
| 65 |
|
| 66 |
+
output_video = gr.Video(label="π½οΈ Final Video")
|
| 67 |
+
output_script = gr.Textbox(label="π AI Generated Script")
|
| 68 |
|
| 69 |
generate_btn.click(fn=full_pipeline, inputs=input_prompt, outputs=[output_video, output_script])
|
| 70 |
|