Spaces:
Running
Running
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) | |
def home(): | |
return render_template("index.html") | |
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 | |
def serve_static(filename): | |
return send_from_directory("static", filename) | |
if __name__ == "__main__": | |
app.run(debug=True) | |