chiraggupta8769 commited on
Commit
743d607
Β·
verified Β·
1 Parent(s): 677232c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
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 (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"):
@@ -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
- 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,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") # 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
 
 
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