This repository contains a production-ready API for generating videos from text prompts using Hugging Face’s CogVideoX model.
The service is designed to run on H100 GPUs, is fully containerized with Docker, and includes monitoring, logging, and error handling.
This repository includes all required deliverables for the assignment:
app.py, Dockerfile)/docs)/generate)/status/{job_id})/video/{job_id})/health)
.
├── app.py # Main FastAPI application
├── requirements.txt # Python dependencies
├── Dockerfile # Containerization
├── output\_videos/ # Generated MP4s (created automatically)
├── logs/ # Application logs (created automatically)
├── docs/ # Documentation assets (e.g., diagram)
└── README.md # Documentation
The system is built around a modular design for reliability and maintainability.

.mp4 filesgit clone https://github.com/your-username/video-gen-api.git
cd video-gen-api
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 8000
Swagger UI available at: http://localhost:8000/docs
docker build -t video-gen-api .
docker run --gpus all -p 8000:8000 video-gen-api
--gpus all ensures GPU acceleration on H100Submit a video generation request.
Request:
{
"prompt": "A squirrel riding a skateboard in Times Square",
"num_frames": 49,
"guidance_scale": 4.5,
"seed": 42,
"fps": 12
}
Response:
{
"job_id": "job_20250914_121030",
"status": "processing"
}
Check job progress.
{
"job_id": "job_20250914_121030",
"status": "completed"
}
Retrieve completed .mp4 file.
Returns binary video data (video/mp4).
System health metrics.
{
"cpu_usage": 12.5,
"memory_usage": 43.1,
"gpu_usage": 54.3,
"active_jobs": 1,
"completed_jobs": 2
}
To demonstrate how the API can be used end-to-end, below is a simple Python script. This script:
import time
import requests
BASE_URL = "http://localhost:8000" # Change if running remotely
def main():
# 1. Submit a generation request
payload = {
"prompt": "A squirrel riding a skateboard in Times Square",
"num_frames": 49,
"guidance_scale": 4.5,
"seed": 42,
"fps": 12
}
print("[*] Submitting job...")
resp = requests.post(f"{BASE_URL}/generate", json=payload)
resp.raise_for_status()
job = resp.json()
job_id = job["job_id"]
print(f"[+] Job submitted: {job_id}, status={job['status']}")
# 2. Poll until job is completed
while True:
status_resp = requests.get(f"{BASE_URL}/status/{job_id}")
status_resp.raise_for_status()
status = status_resp.json()["status"]
print(f"[*] Current status: {status}")
if status == "completed":
break
if status == "failed":
print("[!] Job failed.")
return
time.sleep(5)
# 3. Retrieve video
print("[*] Downloading video...")
video_resp = requests.get(f"{BASE_URL}/video/{job_id}")
if video_resp.status_code == 200:
out_path = f"{job_id}.mp4"
with open(out_path, "wb") as f:
f.write(video_resp.content)
print(f"[+] Video saved to {out_path}")
else:
print(f"[!] Could not download video: {video_resp.text}")
# 4. Check system health
print("[*] Checking system health...")
health_resp = requests.get(f"{BASE_URL}/health")
health_resp.raise_for_status()
print("[+] System Health:", health_resp.json())
if __name__ == "__main__":
main()
Run it with:
python demo.py
nvidia-smi)num_frames or use smaller batch sizes--gpus all)logs/app_YYYYMMDD.log for stack tracesCOMPLETED status before calling /video/{job_id}/health endpoint for CPU, RAM, GPU metricsMIT License – Free to use and modify.
8 commits
Python
88.3%
Dockerfile
11.7%
This repository contains a production-ready API for generating videos from text prompts using Hugging Face’s CogVideoX model.
The service is designed to run on H100 GPUs, is fully containerized with Docker, and includes monitoring, logging, and error handling.
This repository includes all required deliverables for the assignment:
app.py, Dockerfile)/docs)/generate)/status/{job_id})/video/{job_id})/health)
.
├── app.py # Main FastAPI application
├── requirements.txt # Python dependencies
├── Dockerfile # Containerization
├── output\_videos/ # Generated MP4s (created automatically)
├── logs/ # Application logs (created automatically)
├── docs/ # Documentation assets (e.g., diagram)
└── README.md # Documentation
The system is built around a modular design for reliability and maintainability.

.mp4 filesgit clone https://github.com/your-username/video-gen-api.git
cd video-gen-api
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 8000
Swagger UI available at: http://localhost:8000/docs
docker build -t video-gen-api .
docker run --gpus all -p 8000:8000 video-gen-api
--gpus all ensures GPU acceleration on H100Submit a video generation request.
Request:
{
"prompt": "A squirrel riding a skateboard in Times Square",
"num_frames": 49,
"guidance_scale": 4.5,
"seed": 42,
"fps": 12
}
Response:
{
"job_id": "job_20250914_121030",
"status": "processing"
}
Check job progress.
{
"job_id": "job_20250914_121030",
"status": "completed"
}
Retrieve completed .mp4 file.
Returns binary video data (video/mp4).
System health metrics.
{
"cpu_usage": 12.5,
"memory_usage": 43.1,
"gpu_usage": 54.3,
"active_jobs": 1,
"completed_jobs": 2
}
To demonstrate how the API can be used end-to-end, below is a simple Python script. This script:
import time
import requests
BASE_URL = "http://localhost:8000" # Change if running remotely
def main():
# 1. Submit a generation request
payload = {
"prompt": "A squirrel riding a skateboard in Times Square",
"num_frames": 49,
"guidance_scale": 4.5,
"seed": 42,
"fps": 12
}
print("[*] Submitting job...")
resp = requests.post(f"{BASE_URL}/generate", json=payload)
resp.raise_for_status()
job = resp.json()
job_id = job["job_id"]
print(f"[+] Job submitted: {job_id}, status={job['status']}")
# 2. Poll until job is completed
while True:
status_resp = requests.get(f"{BASE_URL}/status/{job_id}")
status_resp.raise_for_status()
status = status_resp.json()["status"]
print(f"[*] Current status: {status}")
if status == "completed":
break
if status == "failed":
print("[!] Job failed.")
return
time.sleep(5)
# 3. Retrieve video
print("[*] Downloading video...")
video_resp = requests.get(f"{BASE_URL}/video/{job_id}")
if video_resp.status_code == 200:
out_path = f"{job_id}.mp4"
with open(out_path, "wb") as f:
f.write(video_resp.content)
print(f"[+] Video saved to {out_path}")
else:
print(f"[!] Could not download video: {video_resp.text}")
# 4. Check system health
print("[*] Checking system health...")
health_resp = requests.get(f"{BASE_URL}/health")
health_resp.raise_for_status()
print("[+] System Health:", health_resp.json())
if __name__ == "__main__":
main()
Run it with:
python demo.py
nvidia-smi)num_frames or use smaller batch sizes--gpus all)logs/app_YYYYMMDD.log for stack tracesCOMPLETED status before calling /video/{job_id}/health endpoint for CPU, RAM, GPU metricsMIT License – Free to use and modify.
8 commits
Python
88.3%
Dockerfile
11.7%