File size: 1,405 Bytes
255df7f
2fde59e
8e3c369
96f419b
 
8e3c369
 
 
7c9ccc5
255df7f
18ee134
255df7f
8e3c369
 
 
ea26699
 
3f6bd82
3bde6e5
 
b153e4f
 
2fde59e
1125603
2fde59e
 
 
 
 
 
 
 
 
 
 
7c9ccc5
2fde59e
 
 
1125603
 
 
6ec513d
2fde59e
 
89193d4
3bde6e5
2fde59e
3bde6e5
1125603
18ee134
2fde59e
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
from flask import Flask, request, jsonify, send_file
from moviepy.editor import ColorClip, ImageClip, concatenate_videoclips, VideoFileClip
import traceback
import uuid
import glob
import os
from image_fetcher import main
from video import create_text_image
from video2 import video_func

app = Flask(__name__)

@app.route("/")
def home():
    return "Flask Video Generator is Running"

@app.route("/generate", methods=["POST"])
def generate_video():
    try:
        data = request.get_json()
        id = data["id"]
        lines = data["lines"]

        image_folder = "/tmp/images"
        image_olst = []

        # 1. Create Image
        create_text_image(lines[id], id, image_olst)

        # 2. Generate Video (Only once!)
        video_path = video_func(id, lines)

        # 3. Check video exists
        if not os.path.exists(video_path):
            raise Exception("Video not found: " + video_path)

        print("Generated video at:", video_path)

        # 4. Cleanup images
        image_files = sorted(glob.glob(os.path.join(image_folder, "*.png")))
        for img in image_files:
            os.remove(img)

        # 5. Return video
        return send_file(video_path, mimetype='video/mp4', as_attachment=True)

    except Exception as e:
        traceback.print_exc()
        return jsonify({"error": str(e)}), 500

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)