π 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
- Go to https://replicate.com
- Sign up for a free account
- Go to https://replicate.com/account/api-tokens
- Copy your API token
2. Install Replicate Python Client
pip install replicate
3. Create Replicate Backend
Create a new file backend_replicate.py:
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:
REPLICATE_API_TOKEN=r8_your_token_here
5. Run the Replicate Backend
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:
Hailuo Video-01 (MiniMax) - The real Hailuo model!
replicate.run("minimax/video-01", input={"prompt": "..."})CogVideoX
replicate.run("lucataco/cogvideox-5b", input={"prompt": "..."})Kling v1.6
replicate.run("fofr/kling-v1.6-standard", input={"prompt": "..."})
Image-to-Video Models:
Stable Video Diffusion
replicate.run("stability-ai/stable-video-diffusion", input={"image": "..."})Hailuo Image-to-Video
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:
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
- Real Hailuo Model: The actual MiniMax video-01
- No Space Sleeping: Always available
- Better Performance: Optimized infrastructure
- Predictable Costs: Pay per generation
- Multiple Models: Access to many models
- 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! π