File size: 3,591 Bytes
54ed165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""
Simple backend with multiple fallback options
Uses less congested models and provides demo mode
"""

from flask import Flask, request, jsonify
from flask_cors import CORS
import os
import logging
from datetime import datetime

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)

app = Flask(__name__)
CORS(app)

# Sample videos for demo mode
DEMO_VIDEOS = [
    "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
    "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4",
    "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
    "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4",
]

@app.route('/health', methods=['GET'])
def health():
    return jsonify({
        'status': 'healthy',
        'mode': 'demo',
        'message': 'Demo mode - returns sample videos for testing'
    })

@app.route('/models', methods=['GET'])
def list_models():
    return jsonify({
        'models': {
            'demo': {
                'name': 'Demo Mode (Instant)',
                'description': 'Returns sample videos instantly for testing UI',
                'type': 'text-to-video'
            },
            'local': {
                'name': 'Local Generation (Recommended)',
                'description': 'Run CogVideoX locally on your computer',
                'type': 'text-to-video'
            }
        }
    })

@app.route('/generate-video', methods=['POST'])
def generate_video():
    try:
        data = request.json
        prompt = data.get('prompt', '').strip()
        
        if not prompt:
            return jsonify({'error': 'Prompt is required'}), 400
        
        logger.info(f"Demo mode: Returning sample video for prompt: {prompt[:100]}")
        
        # Return a sample video
        import random
        video_url = random.choice(DEMO_VIDEOS)
        
        return jsonify({
            'video_url': video_url,
            'prompt': prompt,
            'model': 'demo',
            'model_name': 'Demo Mode (Sample Video)',
            'timestamp': datetime.now().isoformat(),
            'note': '⚠️ This is a demo video. All online AI services are currently overloaded. Recommendation: Use local generation (backend_local.py) for real AI videos.'
        })
        
    except Exception as e:
        logger.error(f"Error: {str(e)}")
        return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
    print("=" * 70)
    print("🎬 DEMO MODE - Simple Backend")
    print("=" * 70)
    print("")
    print("⚠️  IMPORTANT: All online AI video services are currently overloaded!")
    print("")
    print("This demo backend returns sample videos to test the UI.")
    print("")
    print("For REAL AI video generation, you have 2 options:")
    print("")
    print("1. 🖥️  LOCAL GENERATION (Recommended):")
    print("   - Run: python backend_local.py")
    print("   - Open: index_local.html")
    print("   - Free, private, works offline")
    print("   - Takes 30-120s (GPU) or 5-10min (CPU)")
    print("")
    print("2. 💰 PAID API (Replicate Pro):")
    print("   - Upgrade to Replicate Pro account")
    print("   - Run: python backend_replicate.py")
    print("   - Fast but costs ~$0.05-0.10 per video")
    print("")
    print("=" * 70)
    print("Starting demo server on http://localhost:5000")
    print("=" * 70)
    
    app.run(host='0.0.0.0', port=5000, debug=False)