Spaces:
Sleeping
Sleeping
metadata
title: Short Video Maker
emoji: π¬
colorFrom: purple
colorTo: pink
sdk: docker
app_port: 8880
Short Video Maker - Python FastAPI π¬
Complete Python/FastAPI migration of the short-video-maker for Hugging Face Spaces Docker deployment.
β¨ Features
- ποΈ Text-to-speech narration via Kokoro (cloud API)
- π Automatic caption generation using Whisper
- π₯ Background videos from Pexels API
- π΅ Background music with mood selection
- π± Portrait (9:16) and landscape (16:9) support
- π Web UI and REST API
- π Optimized for Hugging Face Spaces deployment
ποΈ Project Structure
video_bot_python/
βββ app.py # Main FastAPI application
βββ config.py # Configuration management
βββ requirements.txt # Python dependencies
βββ Dockerfile # HF Spaces Docker config
βββ models/
β βββ schemas.py # Pydantic models
βββ routers/
β βββ api.py # REST API endpoints
βββ video_creator/
β βββ short_creator.py # Main orchestrator
β βββ music_manager.py # Music file management
β βββ libraries/
β βββ tts_client.py # Kokoro TTS client
β βββ whisper_client.py # Faster-whisper integration
β βββ pexels_client.py # Pexels API client
β βββ ffmpeg_utils.py # Audio processing
β βββ video_composer.py # MoviePy video composition
βββ static/
β βββ index.html # Web UI
β βββ style.css # UI styles
β βββ app.js # UI logic
β βββ music/ # Background music files
βββ tests/
βββ test_api.py # Unit tests
βββ integration_test.py # E2E test
π Quick Start
Local Development
- Clone and install:
cd video_bot_python
pip install -r requirements.txt
- Configure environment:
cp .env.example .env
# Edit .env with your API keys:
# - PEXELS_API_KEY (from https://www.pexels.com/api/)
# - HF_TTS (your TTS endpoint URL)
- Run the server:
python app.py
# Or with uvicorn:
uvicorn app:app --host 0.0.0.0 --port 8880 --reload
- Access:
- Web UI: http://localhost:8880
- API docs: http://localhost:8880/docs
- Health: http://localhost:8880/health
Docker
# Build
docker build -t short-video-maker-python .
# Run
docker run -p 8880:8880 \
-e PEXELS_API_KEY="your_key" \
-e HF_TTS="https://your-tts.hf.space" \
-v $(pwd)/data:/data \
short-video-maker-python
Hugging Face Spaces (Deploy)
Create Space:
- Go to https://huggingface.co/new-space
- Select "Docker" SDK
- Clone your space repository
Push code:
git clone https://huggingface.co/spaces/YOUR_USERNAME/short-video-maker
cp -r video_bot_python/* short-video-maker/
cd short-video-maker
git add .
git commit -m "Initial Python FastAPI version"
git push
Configure secrets:
- Go to Space Settings β Repository Secrets
- Add:
PEXELS_API_KEY - Add:
HF_TTS
Wait for build and access:
https://YOUR_USERNAME-short-video-maker.hf.space
π‘ API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/api/short-video |
POST | Create new video |
/api/short-video/{id}/status |
GET | Check video status |
/api/short-video/{id} |
GET | Download video |
/api/short-videos |
GET | List all videos |
/api/short-video/{id} |
DELETE | Delete video |
/api/voices |
GET | List TTS voices |
/api/music-tags |
GET | List music moods |
Example: Create Video
curl -X POST http://localhost:8880/api/short-video \
-H "Content-Type: application/json" \
-d '{
"scenes": [
{
"text": "Hello world!",
"searchTerms": ["nature", "forest"]
}
],
"config": {
"voice": "af_heart",
"music": "chill",
"orientation": "portrait"
}
}'
βοΈ Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
PEXELS_API_KEY |
β Yes | - | Pexels API key |
HF_TTS |
β Yes | - | TTS service URL |
PORT |
No | 8880 | Server port |
LOG_LEVEL |
No | info | Logging level |
WHISPER_MODEL |
No | tiny.en | Whisper model |
DATA_DIR_PATH |
No | auto | Data directory |
DOCKER |
No | false | Docker mode |
π§ͺ Testing
Unit tests:
pytest tests/test_api.py -v
Integration test:
# Set environment variables first
export PEXELS_API_KEY="your_key"
export HF_TTS="https://your-tts.hf.space"
python tests/integration_test.py
π Migration from Node.js
This Python version maintains API compatibility with the original Node.js version:
| Component | Node.js | Python |
|---|---|---|
| Framework | Express.js | FastAPI |
| Video composition | Remotion | MoviePy |
| Captions | Whisper.cpp | faster-whisper |
| TTS | Kokoro-js | HTTP client (cloud) |
| Media search | Pexels API | Pexels API |
| Audio | FFmpeg | FFmpeg |
API endpoints remain identical - existing clients will work without changes!
π Configuration Options
{
"voice": "af_heart", # TTS voice
"music": "chill", # Music mood (sad/happy/chill/dark/etc)
"musicVolume": "high", # low/medium/high/muted
"orientation": "portrait", # portrait/landscape
"captionPosition": "bottom", # top/center/bottom
"captionBackgroundColor": "blue",
"paddingBack": 1000 # End padding in milliseconds
}
π΅ Adding Music
- Copy MP3 files to
static/music/ - (Optional) Create
static/music/music_metadata.json:
{
"song1.mp3": {"mood": "chill"},
"song2.mp3": {"mood": "happy"}
}
π Troubleshooting
"PEXELS_API_KEY is required"
- Set the environment variable or add to
.envfile
"HF_TTS is required"
- Set your TTS endpoint URL (must be accessible)
"No music files found"
- Copy MP3 files to
static/music/directory
Video processing takes too long
- Use
tiny.enWhisper model (faster) - Reduce video length
- Use fewer scenes
Out of memory during rendering
- Increase container memory
- Reduce
VIDEO_CACHE_SIZE_IN_BYTES - Use shorter videos
ποΈ Development
Install dev dependencies:
pip install pytest pytest-asyncio httpx black
Format code:
black .
π License
MIT
π Credits
- Original Node.js version by David Gyori
- Remotion β MoviePy
- Whisper β faster-whisper
- Pexels for video content
- FFmpeg for media processing