File size: 5,557 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | # π Using Replicate API for Real Hailuo (MiniMax) Video Generation
If Hugging Face Spaces are not working, you can use **Replicate API** which has the actual **Hailuo video-01 model** by MiniMax!
## π Why Replicate?
- β
**Real Hailuo Model**: The actual MiniMax video-01 model
- β
**Reliable**: Always available, no sleeping spaces
- β
**Fast**: Optimized infrastructure
- β
**Free Tier**: $5 free credits to start
## π Setup Instructions
### 1. Get Replicate API Token
1. Go to https://replicate.com
2. Sign up for a free account
3. Go to https://replicate.com/account/api-tokens
4. Copy your API token
### 2. Install Replicate Python Client
```bash
pip install replicate
```
### 3. Create Replicate Backend
Create a new file `backend_replicate.py`:
```python
from flask import Flask, request, jsonify
from flask_cors import CORS
import replicate
import os
from dotenv import load_dotenv
from datetime import datetime
import logging
load_dotenv()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = Flask(__name__)
CORS(app)
# Set your Replicate API token
REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
if REPLICATE_API_TOKEN:
os.environ['REPLICATE_API_TOKEN'] = REPLICATE_API_TOKEN
@app.route('/health', methods=['GET'])
def health():
return jsonify({'status': 'healthy', 'service': 'Replicate API'})
@app.route('/generate-video', methods=['POST'])
def generate_video():
try:
data = request.json
prompt = data.get('prompt', '')
if not prompt:
return jsonify({'error': 'Prompt is required'}), 400
logger.info(f"Generating video with Hailuo: {prompt[:100]}")
# Use the real Hailuo (MiniMax) model on Replicate
output = replicate.run(
"minimax/video-01",
input={
"prompt": prompt,
"prompt_optimizer": True
}
)
# Output is a video URL
video_url = output if isinstance(output, str) else output[0]
logger.info(f"Video generated: {video_url}")
return jsonify({
'video_url': video_url,
'prompt': prompt,
'model': 'hailuo-minimax',
'model_name': 'Hailuo Video-01 (MiniMax)',
'timestamp': datetime.now().isoformat()
})
except Exception as e:
logger.error(f"Error: {str(e)}")
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
if not REPLICATE_API_TOKEN:
print("β οΈ Warning: REPLICATE_API_TOKEN not set in .env file")
print("Get your token from: https://replicate.com/account/api-tokens")
app.run(host='0.0.0.0', port=5000, debug=False)
```
### 4. Update .env File
Add your Replicate API token to `.env`:
```env
REPLICATE_API_TOKEN=r8_your_token_here
```
### 5. Run the Replicate Backend
```bash
python3 backend_replicate.py
```
### 6. Use with Your Frontend
The frontend (`index_enhanced.html`) will work with this backend without any changes!
## π¬ Available Models on Replicate
### Text-to-Video Models:
1. **Hailuo Video-01 (MiniMax)** - The real Hailuo model!
```python
replicate.run("minimax/video-01", input={"prompt": "..."})
```
2. **CogVideoX**
```python
replicate.run("lucataco/cogvideox-5b", input={"prompt": "..."})
```
3. **Kling v1.6**
```python
replicate.run("fofr/kling-v1.6-standard", input={"prompt": "..."})
```
### Image-to-Video Models:
1. **Stable Video Diffusion**
```python
replicate.run("stability-ai/stable-video-diffusion", input={"image": "..."})
```
2. **Hailuo Image-to-Video**
```python
replicate.run("minimax/video-01", input={"image": "...", "prompt": "..."})
```
## π° Pricing
- **Free Tier**: $5 free credits (enough for ~50 videos)
- **Pay-as-you-go**: ~$0.10 per video generation
- Much cheaper than running your own GPU!
## π§ Advanced: Multi-Model Support
Create `backend_replicate_multi.py` with multiple models:
```python
MODELS = {
"hailuo": "minimax/video-01",
"cogvideox": "lucataco/cogvideox-5b",
"kling": "fofr/kling-v1.6-standard",
"svd": "stability-ai/stable-video-diffusion"
}
@app.route('/generate-video', methods=['POST'])
def generate_video():
data = request.json
model_id = data.get('model', 'hailuo')
prompt = data.get('prompt', '')
model_name = MODELS.get(model_id, MODELS['hailuo'])
output = replicate.run(model_name, input={"prompt": prompt})
# ... rest of the code
```
## β
Advantages of Replicate
1. **Real Hailuo Model**: The actual MiniMax video-01
2. **No Space Sleeping**: Always available
3. **Better Performance**: Optimized infrastructure
4. **Predictable Costs**: Pay per generation
5. **Multiple Models**: Access to many models
6. **Better Support**: Professional API support
## π Resources
- **Replicate Docs**: https://replicate.com/docs
- **Hailuo Model**: https://replicate.com/minimax/video-01
- **Python Client**: https://github.com/replicate/replicate-python
- **Pricing**: https://replicate.com/pricing
## π― Recommendation
For **production use** or if Hugging Face Spaces keep failing:
- β
Use Replicate API
- β
Get the real Hailuo model
- β
Reliable and fast
- β
Only pay for what you use
For **testing/development**:
- Use Demo Mode in the current app
- Or use Hugging Face Spaces (free but may be slow/unavailable)
---
**Ready to use the real Hailuo model? Set up Replicate now!** π
|