File size: 1,089 Bytes
70b88a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, render_template, request, jsonify, send_from_directory
from diffusers import DiffusionPipeline
import os

app = Flask(__name__)

# Load the AI text-to-video model
pipe = DiffusionPipeline.from_pretrained("ali-vilab/text-to-video-ms-1.7b")

# Ensure static folder exists for saving videos
os.makedirs("static", exist_ok=True)

@app.route("/")
def home():
    return render_template("index.html")

@app.route("/generate", methods=["POST"])
def generate():
    data = request.json
    prompt = data.get("prompt", "")

    if not prompt:
        return jsonify({"error": "No prompt provided"}), 400

    try:
        # Generate video using AI model
        video = pipe(prompt).videos[0]
        video_path = "static/generated_video.mp4"
        video.save(video_path)

        return jsonify({"video_url": video_path})
    except Exception as e:
        return jsonify({"error": str(e)}), 500

@app.route("/static/<path:filename>")
def serve_static(filename):
    return send_from_directory("static", filename)

if __name__ == "__main__":
    app.run(debug=True)