A comprehensive web application built with Gradio that provides an intuitive interface for generating videos using Alibaba's Bailian APIs. Supports three generation modes: text-to-video, image-to-video, and keyframe-to-video generation.
- 🆕 Wan 2.5 Support: Latest models with audio generation and 10s video support
- 🎵 Audio Generation: Auto-generated or custom audio for synchronized videos
- ⏱️ Extended Duration: 5-10 second video generation (upgraded from 5s)
- 🎥 Text-to-Video: Convert text descriptions into high-quality videos
- 🖼️ Image-to-Video: Generate dynamic videos from a single image
- 🎞️ Keyframe-to-Video: Create smooth transitions between start and end frames
- 🎨 Multiple Style Options: Support for cinematic, anime, realistic, and other artistic styles
- 📐 Flexible Aspect Ratios: Support for 16:9, 1:1, 9:16 and other ratios
- ⚙️ Advanced Settings: Support for negative prompts, seed control, and fine-tuning
- 🤖 Smart Model Selection: Automatically choose optimal models based on generation mode
- 📱 Responsive Interface: Beautiful and user-friendly interface with real-time feedback
- 📊 Status Tracking: Detailed progress and error reporting
- ☁️ OSS Integration: Optional Alibaba Cloud OSS storage support
- 🎵 Audio Generation: Automatically generate synchronized audio or use custom audio URLs
- ⏰ Longer Videos: Create 5-10 second videos (doubled from previous 5s limit)
- 📐 1080P Support: Full high-definition video output across all Wan 2.5 models
- 📝 Extended Prompts: Support for up to 2000 characters (upgraded from 1000)
- 🎬 24fps Frame Rate: Smoother, cinema-quality video playback
- 🔧 Backward Compatible: All Wan 2.2 models remain available
For detailed Wan 2.5 updates, see WAN_2.5_UPDATE.md
- Python 3.13 or higher
- Valid Alibaba Bailian API key
- Stable internet connection
-
Clone the repository:
git clone https://github.com/PCcoding666/WAN_GATEWAY.git cd Wan_Gateway -
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables: Copy
.env.exampleto.envand fill in the configuration:cp .env.example .env # Edit .env file and enter your API key DASHSCOPE_API_KEY=your_api_key_here -
Run the application:
python main.py
-
Open browser and visit
http://localhost:7860
Test all features without starting the web interface:
python demo.pyThe demo includes:
- Configuration for all three generation modes
- Service factory functionality showcase
- Configuration option validation
- API endpoint setup verification
- Model compatibility testing
The application supports three video generation modes:
- Processing Time: 1-2 minutes
- Description: Generate videos through detailed text descriptions
- Available Models:
- 🆕 wan2.5-t2v-preview (Recommended) - Audio support, 5-10s, 1080P
- wan2.2-t2v-plus - Latest high-quality model
- wanx2.1-t2v-turbo - Fast generation
- wanx2.1-t2v-plus - High-quality generation
- Resolution Support: 480P-1080P
- Features:
- 🎵 Audio generation (Wan 2.5)
- ⏱️ 5-10 second duration (Wan 2.5)
- Style control, aspect ratio
- Negative prompts, seed control
- Up to 2000 characters prompt (Wan 2.5)
- Processing Time: 7-10 minutes
- Description: Generate dynamic videos from a single image
- Available Models:
- 🆕 wan2.5-i2v-preview (Recommended) - Audio support, 5-10s, 1080P
- wan2.2-i2v-flash - Fastest generation
- wan2.2-i2v-plus - Latest high-quality
- wanx2.1-i2v-plus, wanx2.1-i2v-turbo
- Image Requirements: JPEG/PNG/BMP/WEBP, max 10MB, 360-2000px dimensions
- Features:
- 🎵 Audio generation (Wan 2.5)
- ⏱️ 5-10 second duration (Wan 2.5)
- Optional text guidance, style control
- Processing Time: 7-10 minutes
- Description: Generate smooth transitions between start and end frames
- Available Models: wanx2.1-kf2v-plus
- Requirements: Two images with similar composition (start and end frames)
- Features: Optional transition guidance, style control
-
Select Generation Mode: Choose the desired generation mode at the top of the interface
-
Input Content (based on selected mode):
- Text Mode: Enter video description
- Example: "A peaceful sunset on a mountain ridge with birds flying"
- Image Mode: Upload an image
- Keyframe Mode: Upload start and end images
- Text Mode: Enter video description
-
Choose Style: Select from available artistic styles
- Auto (recommended), Cinematic, Anime, Realistic, Abstract, Documentary, Commercial
-
Set Aspect Ratio: Choose video dimensions
- 16:9 (widescreen), 1:1 (square), 9:16 (portrait)
-
Click "Generate Video": Wait for AI to create your video
For text-to-video mode, expand the "Advanced Settings" section for more control:
-
Negative Prompt: Specify content to avoid in the video
- Example: "blurry, low quality, distorted"
-
Seed: Enter a number for reproducible results
- Same seed + same prompt = similar videos
-
Model Selection: Choose different models based on needs
- wan2.2-t2v-plus: Latest high-quality model (recommended)
- wanx2.1-t2v-turbo: Fast generation model
- wanx2.1-t2v-plus: High-quality generation model
python main.py [OPTIONS]
Options:
--host TEXT Bind server to specified host (default: 127.0.0.1)
--port INTEGER Port to run server on (default: 7860)
--share Create public link for the application
--debug Enable debug mode with verbose logging
--check-env Check environment configuration and exit
--help Show this help message and exit
# Run on different port
python main.py --port 8080
# Create public link (for sharing)
python main.py --share
# Debug mode with verbose logging
python main.py --debug
# Check environment configuration
python main.py --check-env
# Bind to all network interfaces
python main.py --host 0.0.0.0Wan_Gateway/
├── src/ # Core source code directory
│ ├── __init__.py # Package initialization
│ ├── config.py # Configuration management
│ ├── base_video_service.py # Base video service class
│ ├── text_to_video_service.py # Text-to-video service
│ ├── image_to_video_service.py # Image-to-video service
│ ├── keyframe_to_video_service.py # Keyframe-to-video service
│ ├── video_service_factory.py # Service factory and multi-modal app
│ ├── gradio_app.py # Gradio web interface
│ ├── oss_service.py # OSS cloud storage service
│ └── utils.py # Utility functions
├── doc/ # Chinese documentation
│ ├── README_zh.md # Chinese README
│ ├── API_zh.md # Chinese API documentation
│ ├── DEPLOYMENT_zh.md # Chinese deployment guide
│ ├── CONTRIBUTING_zh.md # Chinese contributing guide
│ └── CHANGELOG_zh.md # Chinese changelog
├── .env.example # Environment variables template
├── requirements.txt # Python dependencies
├── pyproject.toml # Project configuration file
├── main.py # Application entry point
├── demo.py # Feature demonstration script
├── Dockerfile # Docker container configuration
├── docker-compose.yml # Docker Compose configuration
├── deploy-production.sh # Production deployment script
├── README.md # Project documentation (English)
├── API.md # API documentation (English)
├── DEPLOYMENT.md # Deployment guide (English)
├── CONTRIBUTING.md # Contributing guide (English)
└── CHANGELOG.md # Version changelog (English)
| Variable | Description | Required | Default |
|---|---|---|---|
DASHSCOPE_API_KEY |
Alibaba Bailian API key | Yes | - |
OSS_ACCESS_KEY_ID |
OSS access key ID (optional) | No | - |
OSS_ACCESS_KEY_SECRET |
OSS access key secret (optional) | No | - |
OSS_ENDPOINT |
OSS service endpoint (optional) | No | https://oss-cn-hangzhou.aliyuncs.com |
OSS_BUCKET_NAME |
OSS bucket name (optional) | No | wan-gateway-images |
Key configuration options in src/config.py:
# UI Settings
MAX_PROMPT_LENGTH = 1000 # Maximum prompt length
DEFAULT_STYLE = "<auto>" # Default style selection
DEFAULT_ASPECT_RATIO = "16:9" # Default aspect ratio
DEFAULT_MODEL = "wan2.2-t2v-plus" # Default model
# API Settings
MAX_RETRIES = 3 # Maximum retry attempts
POLLING_INTERVAL = 2 # Text-to-video polling interval (seconds)
KEYFRAME_POLLING_INTERVAL = 30 # Image/keyframe polling interval (seconds)
REQUEST_TIMEOUT = 30 # Request timeout (seconds)
MAX_POLL_TIME = 300 # Text generation max polling time (5 minutes)
KEYFRAME_MAX_POLL_TIME = 900 # Keyframe generation max polling time (15 minutes)
# Image Upload Settings
IMAGE_UPLOAD_CONFIG = {
"max_size_mb": 10,
"allowed_formats": ["JPEG", "JPG", "PNG", "BMP", "WEBP"],
"min_dimension": 360,
"max_dimension": 2000
}| Style | Description | Use Cases |
|---|---|---|
| Auto | Automatic style selection | General use, recommended |
| Cinematic | Movie-quality with dramatic lighting | Professional videos, trailers |
| Anime | Animation/cartoon style | Character-focused content |
| Realistic | Photorealistic rendering | Documentary-style content |
| Abstract | Artistic non-realistic style | Creative artistic videos |
| Documentary | Natural, informational style | Educational content |
| Commercial | Polished advertising style | Marketing materials |
| Ratio | Description | Use Cases |
|---|---|---|
| 16:9 | Widescreen format | YouTube, web videos, presentations |
| 1:1 | Square format | Instagram posts, social media |
| 9:16 | Portrait/vertical format | TikTok, Instagram stories, mobile |
❌ Configuration error: DASHSCOPE_API_KEY environment variable is required
Solution: Ensure your .env file contains a valid API key:
DASHSCOPE_API_KEY=your_actual_api_key_here❌ Import error: No module named 'gradio'
Solution: Install dependencies:
pip install -r requirements.txt❌ Connection error - please check your internet connection
Solutions:
- Check internet connection
- Verify API key is valid and has quota
- Try again later (may be rate limited)
❌ Generation failed: Invalid request
Solutions:
- Ensure prompt is descriptive and appropriate
- Try different styles or aspect ratios
- Check prompt is within length limit (1000 characters)
Enable debug mode for detailed logging:
python main.py --debugThis provides detailed output including:
- API request/response details
- Error stack traces
- Performance metrics
- Configuration validation steps
-
Descriptive Prompts: Include details about:
- Scene setting and environment
- Lighting conditions (sunset, bright, dim)
- Camera movement (pan, zoom, static)
- Mood and atmosphere
-
Optimal Prompt Length:
- Target 50-200 characters
- Include key visual elements
- Avoid overly complex descriptions
-
Style Selection:
- Use "Auto" for general content
- Choose specific styles for targeted aesthetics
- "Cinematic" works well for dramatic scenes
-
Aspect Ratio Selection:
- 16:9 for most web/YouTube content
- 1:1 for social media posts
- 9:16 for mobile-first content
-
System Requirements:
- Stable internet connection
- Modern web browser
- Sufficient system memory
-
API Usage:
- Respect rate limiting
- Monitor quota usage
- Use caching for repeated requests
This application integrates with Alibaba Bailian's multi-modal video generation APIs:
- Text-to-Video: wan2.2-t2v-plus, wanx2.1-t2v-turbo, wanx2.1-t2v-plus
- Image-to-Video: wan2.2-i2v-flash, wan2.2-i2v-plus, wanx2.1-i2v-plus, wanx2.1-i2v-turbo
- Keyframe-to-Video: wanx2.1-kf2v-plus
- Asynchronous Processing with task polling
- Status Monitoring (PENDING → RUNNING → SUCCEEDED/FAILED)
- Automatic Retry for failed requests
- Timeout Handling (5 minutes for text, 15 minutes max for image/keyframe)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Ensure code quality and documentation
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For detailed guidelines, see CONTRIBUTING.md.
This project is licensed under the MIT License - see the LICENSE file for details.
- Alibaba Cloud for providing Bailian multi-modal video generation APIs
- Gradio for the excellent web interface framework
- Python Community for outstanding libraries and tools
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Run environment check:
python main.py --check-env - Enable debug mode:
python main.py --debug - Check application logs for detailed error information
For Chinese documentation, see the doc folder.
- ✅ Complete multi-modal video generation functionality
- ✅ Robust error handling and logging
- ✅ Comprehensive documentation
- ✅ Production-ready code
- ✅ Docker and cloud deployment support
- ✅ OSS cloud storage integration
- Python 3.13+
make(optional, for convenience)
- Install dependencies:
pip install -r requirements.txt # OR make install
This project uses pytest for testing.
-
Run all tests:
pytest tests/ # OR make test
-
Run with coverage:
pytest --cov=src tests/ # OR make test-cov
tests/unit/: Unit tests for individual components (Config, Services)tests/integration/: Integration tests simulating full workflowstests/conftest.py: Shared test fixtures and configuration
Built with ❤️ using Python and Gradio