from flask import Flask, request, jsonify, send_file, render_template_string from flask_cors import CORS from huggingface_hub import InferenceClient import tempfile import os import base64 from io import BytesIO from PIL import Image import uuid from pathlib import Path app = Flask(__name__) CORS(app) # Configuration HF_TOKEN = os.environ.get("HF_TOKEN", "your_huggingface_token_here") TEMP_DIR = Path(tempfile.gettempdir()) / "veo_videos" TEMP_DIR.mkdir(exist_ok=True) # Initialize the client client = InferenceClient( provider="fal-ai", api_key=HF_TOKEN, bill_to="huggingface", ) def cleanup_old_files(): """Clean up files older than 1 hour""" import time current_time = time.time() for file_path in TEMP_DIR.glob("*.mp4"): if current_time - file_path.stat().st_mtime > 3600: try: file_path.unlink() except: pass # HTML Template for the website HTML_TEMPLATE = """
Powered by Veo 3.1 Fast Model
Generating your video... This may take a minute.
Animating your image... This may take a minute.
Use these endpoints to integrate video generation into your applications.
Endpoint: POST /api/text-to-video
Endpoint: POST /api/image-to-video