freeai-app commited on
Commit
4ae9ea4
·
verified ·
1 Parent(s): 2440898

Create app-cpu.py

Browse files
Files changed (1) hide show
  1. app-cpu.py +57 -0
app-cpu.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gtts import gTTS
3
+ from moviepy.editor import *
4
+ from PIL import Image
5
+ import tempfile
6
+ import os
7
+
8
+ # -----------------------------------------------------
9
+ # Function: Generate video (text → speech + static background)
10
+ # -----------------------------------------------------
11
+ def generate_video(prompt, affirmation, with_visuals):
12
+ # Create speech
13
+ text = f"{prompt}. {affirmation}" if affirmation else prompt
14
+ tts = gTTS(text=text, lang="en")
15
+ temp_audio = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
16
+ tts.save(temp_audio.name)
17
+
18
+ # Background (no AI visuals, just white image for now)
19
+ bg_img = Image.new("RGB", (720, 480), color=(255, 255, 255))
20
+ bg_path = tempfile.NamedTemporaryFile(delete=False, suffix=".png").name
21
+ bg_img.save(bg_path)
22
+
23
+ # Make video
24
+ clip = ImageClip(bg_path).set_duration(15) # 15 sec video
25
+ audioclip = AudioFileClip(temp_audio.name)
26
+ final = clip.set_audio(audioclip)
27
+
28
+ out_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
29
+ final.write_videofile(out_path, fps=24)
30
+
31
+ return out_path
32
+
33
+ # -----------------------------------------------------
34
+ # Gradio Interface
35
+ # -----------------------------------------------------
36
+ with gr.Blocks() as demo:
37
+ gr.Markdown("## ✨ Journal & Affirmation App (CPU Safe Version) ✨")
38
+
39
+ with gr.Row():
40
+ prompt_in = gr.Textbox(label="Journal Prompt / Affirmation")
41
+ affirmation_in = gr.Textbox(label="Extra Affirmation (optional)")
42
+
43
+ with gr.Row():
44
+ visuals_in = gr.Checkbox(label="(No AI visuals in this version)", value=False, interactive=False)
45
+
46
+ generate_btn = gr.Button("🎬 Generate Video")
47
+
48
+ output_video = gr.Video(label="Generated Video")
49
+
50
+ def run(prompt, affirmation, visuals):
51
+ return generate_video(prompt, affirmation, visuals)
52
+
53
+ generate_btn.click(run, [prompt_in, affirmation_in, visuals_in], output_video)
54
+
55
+ # Launch
56
+ if __name__ == "__main__":
57
+ demo.launch()