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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NCAKit Complete API Documentation
|
| 2 |
+
|
| 3 |
+
> **Base URL:** `https://YOUR_SPACE.hf.space` or `http://localhost:7860`
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## π Table of Contents
|
| 8 |
+
|
| 9 |
+
1. [Video Creator (Short Videos)](#1-video-creator-short-videos)
|
| 10 |
+
2. [Story Reels (AI Image Videos)](#2-story-reels-ai-image-videos)
|
| 11 |
+
3. [Fact Image (Quote Videos)](#3-fact-image-quote-videos)
|
| 12 |
+
4. [Quiz Reel (Interactive Quizzes)](#4-quiz-reel-interactive-quizzes)
|
| 13 |
+
5. [Text Story (Chat Story Videos)](#5-text-story-chat-story-videos)
|
| 14 |
+
6. [Trends (Google Trends)](#6-trends-google-trends)
|
| 15 |
+
7. [Common Patterns](#7-common-patterns)
|
| 16 |
+
8. [HF Cloud Storage & Download](#8-hf-cloud-storage--download)
|
| 17 |
+
9. [Environment Variables](#9-environment-variables)
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## 1. Video Creator (Short Videos)
|
| 22 |
+
|
| 23 |
+
Create short-form videos with multiple scenes, background videos/images, TTS narration, and background music.
|
| 24 |
+
|
| 25 |
+
### Base Path: `/api`
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
### βΆοΈ POST `/api/short-video` - Create Video
|
| 30 |
+
|
| 31 |
+
Create a new short video with multiple scenes.
|
| 32 |
+
|
| 33 |
+
**Request Body:**
|
| 34 |
+
```json
|
| 35 |
+
{
|
| 36 |
+
"scenes": [
|
| 37 |
+
{
|
| 38 |
+
"text": "Scene 1 narration text",
|
| 39 |
+
"searchTerms": ["nature", "forest", "peaceful"]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"text": "Scene 2 narration text",
|
| 43 |
+
"searchTerms": ["city", "night", "lights"]
|
| 44 |
+
}
|
| 45 |
+
],
|
| 46 |
+
"config": {
|
| 47 |
+
"voice": "af_heart",
|
| 48 |
+
"music": "chill",
|
| 49 |
+
"musicVolume": "medium",
|
| 50 |
+
"captionPosition": "bottom",
|
| 51 |
+
"captionBackgroundColor": "blue",
|
| 52 |
+
"orientation": "portrait",
|
| 53 |
+
"paddingBack": 2000
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
**Scene Parameters:**
|
| 59 |
+
| Field | Type | Required | Description |
|
| 60 |
+
|-------|------|----------|-------------|
|
| 61 |
+
| `text` | string | β
| Narration text (will be converted to TTS) |
|
| 62 |
+
| `searchTerms` | string[] | β
| Keywords for finding background video from Pexels/Pixabay |
|
| 63 |
+
|
| 64 |
+
**Config Parameters:**
|
| 65 |
+
| Field | Type | Default | Options |
|
| 66 |
+
|-------|------|---------|---------|
|
| 67 |
+
| `voice` | string | `af_heart` | See [Voice Options](#voice-options) |
|
| 68 |
+
| `music` | string | `null` | `sad`, `happy`, `chill`, `dark`, `hopeful`, etc. |
|
| 69 |
+
| `musicVolume` | string | `high` | `low`, `medium`, `high`, `muted` |
|
| 70 |
+
| `captionPosition` | string | `bottom` | `top`, `center`, `bottom` |
|
| 71 |
+
| `captionBackgroundColor` | string | `blue` | Any CSS color name |
|
| 72 |
+
| `orientation` | string | `portrait` | `portrait`, `landscape` |
|
| 73 |
+
| `paddingBack` | int | `0` | End screen duration in milliseconds |
|
| 74 |
+
|
| 75 |
+
**Response (201):**
|
| 76 |
+
```json
|
| 77 |
+
{
|
| 78 |
+
"videoId": "abc123def456..."
|
| 79 |
+
}
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
+
|
| 84 |
+
### π GET `/api/short-video/{video_id}/status` - Check Status
|
| 85 |
+
|
| 86 |
+
**Response:**
|
| 87 |
+
```json
|
| 88 |
+
{
|
| 89 |
+
"status": "processing"
|
| 90 |
+
}
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
**Status Values:**
|
| 94 |
+
| Status | Description |
|
| 95 |
+
|--------|-------------|
|
| 96 |
+
| `processing` | Video is being generated |
|
| 97 |
+
| `ready` | Video is ready to download |
|
| 98 |
+
| `failed` | Generation failed |
|
| 99 |
+
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
### β¬οΈ GET `/api/short-video/{video_id}` - Download Video
|
| 103 |
+
|
| 104 |
+
Returns the MP4 video file directly for download.
|
| 105 |
+
|
| 106 |
+
**Headers:**
|
| 107 |
+
```
|
| 108 |
+
Content-Type: video/mp4
|
| 109 |
+
Content-Disposition: attachment; filename="{video_id}.mp4"
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
---
|
| 113 |
+
|
| 114 |
+
### π GET `/api/short-videos` - List All Videos
|
| 115 |
+
|
| 116 |
+
**Response:**
|
| 117 |
+
```json
|
| 118 |
+
{
|
| 119 |
+
"videos": [
|
| 120 |
+
{"id": "abc123", "status": "ready"},
|
| 121 |
+
{"id": "def456", "status": "processing"}
|
| 122 |
+
]
|
| 123 |
+
}
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
---
|
| 127 |
+
|
| 128 |
+
### ποΈ DELETE `/api/short-video/{video_id}` - Delete Video
|
| 129 |
+
|
| 130 |
+
**Response:**
|
| 131 |
+
```json
|
| 132 |
+
{"success": true}
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
---
|
| 136 |
+
|
| 137 |
+
### π€ GET `/api/voices` - List Available Voices
|
| 138 |
+
|
| 139 |
+
**Response:** Array of available Kokoro TTS voices.
|
| 140 |
+
|
| 141 |
+
### π΅ GET `/api/music-tags` - List Music Moods
|
| 142 |
+
|
| 143 |
+
**Response:** Array of available background music moods.
|
| 144 |
+
|
| 145 |
+
---
|
| 146 |
+
|
| 147 |
+
## 2. Story Reels (AI Image Videos)
|
| 148 |
+
|
| 149 |
+
Create story videos with AI-generated images matching the script.
|
| 150 |
+
|
| 151 |
+
### Base Path: `/api`
|
| 152 |
+
|
| 153 |
+
---
|
| 154 |
+
|
| 155 |
+
### βΆοΈ POST `/api/story-reel` - Create Story Reel
|
| 156 |
+
|
| 157 |
+
**Request Body:**
|
| 158 |
+
```json
|
| 159 |
+
{
|
| 160 |
+
"script": "Once upon a time, in a magical forest, a young boy discovered a hidden door...",
|
| 161 |
+
"image_style": "semi-realistic",
|
| 162 |
+
"voice": "af_heart"
|
| 163 |
+
}
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
**Parameters:**
|
| 167 |
+
| Field | Type | Required | Description |
|
| 168 |
+
|-------|------|----------|-------------|
|
| 169 |
+
| `script` | string | β
| Full story script text |
|
| 170 |
+
| `image_style` | string | β | Image generation style |
|
| 171 |
+
| `voice` | string | β | TTS voice |
|
| 172 |
+
|
| 173 |
+
**Image Styles:**
|
| 174 |
+
- `semi-realistic` (default)
|
| 175 |
+
- `anime`
|
| 176 |
+
- `cartoon`
|
| 177 |
+
- `realistic`
|
| 178 |
+
- `watercolor`
|
| 179 |
+
- `sticky animation`
|
| 180 |
+
|
| 181 |
+
**Response (201):**
|
| 182 |
+
```json
|
| 183 |
+
{
|
| 184 |
+
"job_id": "abc123",
|
| 185 |
+
"status": "queued",
|
| 186 |
+
"message": "Video generation started"
|
| 187 |
+
}
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
### π GET `/api/story-reel/{video_id}/status` - Check Status
|
| 193 |
+
|
| 194 |
+
**Response:**
|
| 195 |
+
```json
|
| 196 |
+
{
|
| 197 |
+
"job_id": "abc123",
|
| 198 |
+
"status": "processing",
|
| 199 |
+
"progress": 45,
|
| 200 |
+
"video_url": null,
|
| 201 |
+
"duration": null,
|
| 202 |
+
"error": null
|
| 203 |
+
}
|
| 204 |
+
```
|
| 205 |
+
|
| 206 |
+
**Status Values:**
|
| 207 |
+
- `queued` - Waiting in queue
|
| 208 |
+
- `processing` - Being generated
|
| 209 |
+
- `generating_audio` - TTS in progress
|
| 210 |
+
- `generating_images` - AI images being created
|
| 211 |
+
- `composing_video` - Final video composition
|
| 212 |
+
- `ready` - Complete
|
| 213 |
+
- `failed` - Error occurred
|
| 214 |
+
|
| 215 |
+
---
|
| 216 |
+
|
| 217 |
+
### β¬οΈ GET `/api/story-reel/{video_id}` - Download Video
|
| 218 |
+
|
| 219 |
+
Returns MP4 file or redirects to HF Hub cloud URL.
|
| 220 |
+
|
| 221 |
+
---
|
| 222 |
+
|
| 223 |
+
### π GET `/api/story-reels` - List All Story Reels
|
| 224 |
+
|
| 225 |
+
### ποΈ DELETE `/api/story-reel/{video_id}` - Delete Story Reel
|
| 226 |
+
|
| 227 |
+
### π¨ GET `/api/styles` - List Image Styles
|
| 228 |
+
|
| 229 |
+
### π€ GET `/api/voices` - List TTS Voices
|
| 230 |
+
|
| 231 |
+
---
|
| 232 |
+
|
| 233 |
+
## 3. Fact Image (Quote Videos)
|
| 234 |
+
|
| 235 |
+
Create short videos with AI-generated or stock background images and text overlays.
|
| 236 |
+
|
| 237 |
+
### Base Path: `/api/fact-image`
|
| 238 |
+
|
| 239 |
+
---
|
| 240 |
+
|
| 241 |
+
### βΆοΈ POST `/api/fact-image/` - Create Fact Video
|
| 242 |
+
|
| 243 |
+
**Request Body:**
|
| 244 |
+
```json
|
| 245 |
+
{
|
| 246 |
+
"model": "nvidia",
|
| 247 |
+
"image_prompt": "A serene mountain landscape at sunset with golden light",
|
| 248 |
+
"fact_heading": "DID YOU KNOW?",
|
| 249 |
+
"heading_background": {
|
| 250 |
+
"enabled": true,
|
| 251 |
+
"color": "rgba(255, 109, 128, 0.95)",
|
| 252 |
+
"padding": 22,
|
| 253 |
+
"corner_radius": 28
|
| 254 |
+
},
|
| 255 |
+
"fact_text": "The human brain can process images in as little as 13 milliseconds.",
|
| 256 |
+
"duration": 5
|
| 257 |
+
}
|
| 258 |
+
```
|
| 259 |
+
|
| 260 |
+
**Parameters:**
|
| 261 |
+
| Field | Type | Required | Description |
|
| 262 |
+
|-------|------|----------|-------------|
|
| 263 |
+
| `model` | string | β | `nvidia`, `cloudflare`, `pexels` |
|
| 264 |
+
| `image_prompt` | string | β
| Background image description (10-500 chars) |
|
| 265 |
+
| `fact_heading` | string | β | Heading text (max 50 chars) |
|
| 266 |
+
| `heading_background` | object | β | Heading background style |
|
| 267 |
+
| `fact_text` | string | β
| Main fact text (5-200 chars) |
|
| 268 |
+
| `duration` | int | β | Video duration 4-7 seconds |
|
| 269 |
+
|
| 270 |
+
**Heading Background Options:**
|
| 271 |
+
| Field | Type | Default | Description |
|
| 272 |
+
|-------|------|---------|-------------|
|
| 273 |
+
| `enabled` | bool | `true` | Show/hide background |
|
| 274 |
+
| `color` | string | `rgba(0,0,0,0.45)` | RGBA or hex color |
|
| 275 |
+
| `padding` | int | `22` | Padding around text (5-50) |
|
| 276 |
+
| `corner_radius` | int | `28` | Border radius (0-50) |
|
| 277 |
+
|
| 278 |
+
**Response:**
|
| 279 |
+
```json
|
| 280 |
+
{
|
| 281 |
+
"job_id": "abc123",
|
| 282 |
+
"status": "processing",
|
| 283 |
+
"status_url": "/api/fact-image/abc123/status",
|
| 284 |
+
"download_url": "/api/fact-image/abc123"
|
| 285 |
+
}
|
| 286 |
+
```
|
| 287 |
+
|
| 288 |
+
---
|
| 289 |
+
|
| 290 |
+
### π GET `/api/fact-image/{job_id}/status` - Check Status
|
| 291 |
+
|
| 292 |
+
**Response:**
|
| 293 |
+
```json
|
| 294 |
+
{
|
| 295 |
+
"job_id": "abc123",
|
| 296 |
+
"status": "generating_image",
|
| 297 |
+
"progress": 30,
|
| 298 |
+
"video_url": null,
|
| 299 |
+
"error": null
|
| 300 |
+
}
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
**Status Values:**
|
| 304 |
+
- `queued`
|
| 305 |
+
- `generating_image`
|
| 306 |
+
- `adding_text`
|
| 307 |
+
- `creating_video`
|
| 308 |
+
- `ready`
|
| 309 |
+
- `failed`
|
| 310 |
+
|
| 311 |
+
---
|
| 312 |
+
|
| 313 |
+
### β¬οΈ GET `/api/fact-image/{job_id}` - Download Video
|
| 314 |
+
|
| 315 |
+
### ποΈ DELETE `/api/fact-image/{job_id}` - Delete Video
|
| 316 |
+
|
| 317 |
+
---
|
| 318 |
+
|
| 319 |
+
## 4. Quiz Reel (Interactive Quizzes)
|
| 320 |
+
|
| 321 |
+
Create quiz videos with multiple questions, TTS, and animated answers.
|
| 322 |
+
|
| 323 |
+
### Base Path: `/api/quiz`
|
| 324 |
+
|
| 325 |
+
---
|
| 326 |
+
|
| 327 |
+
### βΆοΈ POST `/api/quiz/generate` - Create Quiz Video
|
| 328 |
+
|
| 329 |
+
**Request Body:**
|
| 330 |
+
```json
|
| 331 |
+
{
|
| 332 |
+
"quizzes": [
|
| 333 |
+
{
|
| 334 |
+
"hook": "GEOGRAPHY QUIZ",
|
| 335 |
+
"question": "What is the highest mountain in the world?",
|
| 336 |
+
"options": {
|
| 337 |
+
"A": "Mount Everest",
|
| 338 |
+
"B": "K2",
|
| 339 |
+
"C": "Kangchenjunga"
|
| 340 |
+
},
|
| 341 |
+
"correct": "A",
|
| 342 |
+
"explain": "Mount Everest stands at 8,848 meters"
|
| 343 |
+
},
|
| 344 |
+
{
|
| 345 |
+
"hook": "SCIENCE QUIZ",
|
| 346 |
+
"question": "What is the chemical symbol for water?",
|
| 347 |
+
"options": {
|
| 348 |
+
"A": "O2",
|
| 349 |
+
"B": "H2O",
|
| 350 |
+
"C": "CO2"
|
| 351 |
+
},
|
| 352 |
+
"correct": "B",
|
| 353 |
+
"explain": "Water is composed of 2 hydrogen and 1 oxygen atom"
|
| 354 |
+
}
|
| 355 |
+
],
|
| 356 |
+
"voice": "af_heart"
|
| 357 |
+
}
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
**Quiz Scene Parameters:**
|
| 361 |
+
| Field | Type | Required | Description |
|
| 362 |
+
|-------|------|----------|-------------|
|
| 363 |
+
| `hook` | string | β | Category label (e.g., "IQ TEST") |
|
| 364 |
+
| `question` | string | β
| The quiz question |
|
| 365 |
+
| `options` | object | β
| Must have exactly A, B, C keys |
|
| 366 |
+
| `correct` | string | β
| Correct answer: "A", "B", or "C" |
|
| 367 |
+
| `explain` | string | β | Explanation shown after reveal |
|
| 368 |
+
|
| 369 |
+
**Response:**
|
| 370 |
+
```json
|
| 371 |
+
{
|
| 372 |
+
"job_id": "abc123",
|
| 373 |
+
"status": "queued",
|
| 374 |
+
"message": "Quiz video generation started with 2 quizzes"
|
| 375 |
+
}
|
| 376 |
+
```
|
| 377 |
+
|
| 378 |
+
---
|
| 379 |
+
|
| 380 |
+
### π GET `/api/quiz/{job_id}/status` - Check Status
|
| 381 |
+
|
| 382 |
+
**Response:**
|
| 383 |
+
```json
|
| 384 |
+
{
|
| 385 |
+
"job_id": "abc123",
|
| 386 |
+
"status": "processing",
|
| 387 |
+
"progress": 60,
|
| 388 |
+
"video_url": null,
|
| 389 |
+
"error": null
|
| 390 |
+
}
|
| 391 |
+
```
|
| 392 |
+
|
| 393 |
+
---
|
| 394 |
+
|
| 395 |
+
### β¬οΈ GET `/api/quiz/video/{job_id}` - Download Video
|
| 396 |
+
|
| 397 |
+
---
|
| 398 |
+
|
| 399 |
+
## 5. Text Story (Chat Story Videos)
|
| 400 |
+
|
| 401 |
+
Create fake iMessage/Messenger chat story videos with gameplay background.
|
| 402 |
+
|
| 403 |
+
### Base Path: `/api/text-story`
|
| 404 |
+
|
| 405 |
+
---
|
| 406 |
+
|
| 407 |
+
### βΆοΈ POST `/api/text-story/generate` - Create Text Story
|
| 408 |
+
|
| 409 |
+
**Request Body (Manual Mode):**
|
| 410 |
+
```json
|
| 411 |
+
{
|
| 412 |
+
"person_a_name": "You",
|
| 413 |
+
"person_b_name": "My Ex",
|
| 414 |
+
"person_b_avatar": "M",
|
| 415 |
+
"messages": [
|
| 416 |
+
{"sender": "B", "text": "Hey... we need to talk"},
|
| 417 |
+
{"sender": "A", "text": "What's up?"},
|
| 418 |
+
{"sender": "B", "text": "I've been thinking about us"},
|
| 419 |
+
{"sender": "B", "text": "A lot actually"},
|
| 420 |
+
{"sender": "A", "text": "What do you mean?"},
|
| 421 |
+
{"sender": "B", "text": "I miss you..."}
|
| 422 |
+
],
|
| 423 |
+
"ending_text": "To be continued...",
|
| 424 |
+
"voice_a": "af_heart",
|
| 425 |
+
"voice_b": "am_fenrir"
|
| 426 |
+
}
|
| 427 |
+
```
|
| 428 |
+
|
| 429 |
+
**Parameters:**
|
| 430 |
+
| Field | Type | Required | Description |
|
| 431 |
+
|-------|------|----------|-------------|
|
| 432 |
+
| `person_a_name` | string | β | Your name (right side, blue bubbles) |
|
| 433 |
+
| `person_b_name` | string | β | Other person's name (shown in header) |
|
| 434 |
+
| `person_b_avatar` | string | β | Avatar letter or emoji |
|
| 435 |
+
| `messages` | array | β
| Chat messages (2-50 messages) |
|
| 436 |
+
| `ending_text` | string | β | Optional ending text overlay |
|
| 437 |
+
| `voice_a` | string | β | Voice for Person A (default: af_heart) |
|
| 438 |
+
| `voice_b` | string | β | Voice for Person B (default: am_fenrir) |
|
| 439 |
+
|
| 440 |
+
**Message Object:**
|
| 441 |
+
| Field | Type | Description |
|
| 442 |
+
|-------|------|-------------|
|
| 443 |
+
| `sender` | string | `"A"` = You (right, blue), `"B"` = Other (left, gray) |
|
| 444 |
+
| `text` | string | Message text (1-500 chars) |
|
| 445 |
+
|
| 446 |
+
> **Note:** The same sender CAN send multiple messages in a row for natural conversation flow!
|
| 447 |
+
|
| 448 |
+
**Response:**
|
| 449 |
+
```json
|
| 450 |
+
{
|
| 451 |
+
"job_id": "abc123",
|
| 452 |
+
"status": "processing",
|
| 453 |
+
"message": "Started generating text story with 6 messages"
|
| 454 |
+
}
|
| 455 |
+
```
|
| 456 |
+
|
| 457 |
+
---
|
| 458 |
+
|
| 459 |
+
### π€ POST `/api/text-story/ai-generate` - AI Generate Conversation
|
| 460 |
+
|
| 461 |
+
Use Groq AI to generate a conversation from a prompt.
|
| 462 |
+
|
| 463 |
+
**Request Body:**
|
| 464 |
+
```json
|
| 465 |
+
{
|
| 466 |
+
"prompt": "A breakup conversation where she reveals she's getting married to someone else",
|
| 467 |
+
"person_a_name": "You",
|
| 468 |
+
"person_b_name": "My Ex",
|
| 469 |
+
"message_count": 7,
|
| 470 |
+
"tone": "emotional"
|
| 471 |
+
}
|
| 472 |
+
```
|
| 473 |
+
|
| 474 |
+
**Parameters:**
|
| 475 |
+
| Field | Type | Default | Options |
|
| 476 |
+
|-------|------|---------|---------|
|
| 477 |
+
| `prompt` | string | - | Conversation scenario |
|
| 478 |
+
| `person_a_name` | string | "You" | - |
|
| 479 |
+
| `person_b_name` | string | "My Ex" | - |
|
| 480 |
+
| `message_count` | int | 7 | Approximate message count |
|
| 481 |
+
| `tone` | string | "emotional" | `emotional`, `funny`, `shocking`, `romantic`, `angry` |
|
| 482 |
+
|
| 483 |
+
**Response:**
|
| 484 |
+
```json
|
| 485 |
+
{
|
| 486 |
+
"messages": [
|
| 487 |
+
{"sender": "B", "text": "Hey..."},
|
| 488 |
+
{"sender": "A", "text": "What's up?"}
|
| 489 |
+
],
|
| 490 |
+
"ending_text": "To be continued..."
|
| 491 |
+
}
|
| 492 |
+
```
|
| 493 |
+
|
| 494 |
+
> **Workflow:** Use `/ai-generate` first β Get messages β Send to `/generate`
|
| 495 |
+
|
| 496 |
+
---
|
| 497 |
+
|
| 498 |
+
### π GET `/api/text-story/{job_id}/status` - Check Status
|
| 499 |
+
|
| 500 |
+
**Response:**
|
| 501 |
+
```json
|
| 502 |
+
{
|
| 503 |
+
"job_id": "abc123",
|
| 504 |
+
"status": "processing",
|
| 505 |
+
"progress": 45,
|
| 506 |
+
"current_step": "Rendering chat UI...",
|
| 507 |
+
"video_url": null,
|
| 508 |
+
"error": null
|
| 509 |
+
}
|
| 510 |
+
```
|
| 511 |
+
|
| 512 |
+
---
|
| 513 |
+
|
| 514 |
+
### β¬οΈ GET `/api/text-story/{job_id}/video` - Download Video
|
| 515 |
+
|
| 516 |
+
---
|
| 517 |
+
|
| 518 |
+
## 6. Trends (Google Trends)
|
| 519 |
+
|
| 520 |
+
Get trending topics and keyword research data.
|
| 521 |
+
|
| 522 |
+
### Base Path: `/api/trends`
|
| 523 |
+
|
| 524 |
+
---
|
| 525 |
+
|
| 526 |
+
### βΆοΈ POST `/api/trends/trending-now` - Get Trending Topics
|
| 527 |
+
|
| 528 |
+
**Request Body:**
|
| 529 |
+
```json
|
| 530 |
+
{
|
| 531 |
+
"country": "bangladesh",
|
| 532 |
+
"limit": 20
|
| 533 |
+
}
|
| 534 |
+
```
|
| 535 |
+
|
| 536 |
+
**Countries:** `united_states`, `united_kingdom`, `india`, `bangladesh`, `japan`, `germany`, `france`, `brazil`, `canada`, `australia`
|
| 537 |
+
|
| 538 |
+
**Response:**
|
| 539 |
+
```json
|
| 540 |
+
{
|
| 541 |
+
"success": true,
|
| 542 |
+
"count": 20,
|
| 543 |
+
"trends": [
|
| 544 |
+
{"rank": 1, "topic": "Cricket World Cup", "country": "bangladesh", "traffic": "100K+"},
|
| 545 |
+
{"rank": 2, "topic": "BPL 2024", "country": "bangladesh", "traffic": "50K+"}
|
| 546 |
+
]
|
| 547 |
+
}
|
| 548 |
+
```
|
| 549 |
+
|
| 550 |
+
---
|
| 551 |
+
|
| 552 |
+
### π POST `/api/trends/keyword-research` - Keyword Research
|
| 553 |
+
|
| 554 |
+
**Request Body:**
|
| 555 |
+
```json
|
| 556 |
+
{
|
| 557 |
+
"keyword": "weight loss",
|
| 558 |
+
"region": "US",
|
| 559 |
+
"timeframe": "today_12m",
|
| 560 |
+
"category": "health",
|
| 561 |
+
"search_type": "web"
|
| 562 |
+
}
|
| 563 |
+
```
|
| 564 |
+
|
| 565 |
+
**Parameters:**
|
| 566 |
+
| Field | Type | Options |
|
| 567 |
+
|-------|------|---------|
|
| 568 |
+
| `timeframe` | string | `now_1h`, `now_4h`, `now_1d`, `now_7d`, `today_1m`, `today_3m`, `today_12m`, `today_5y` |
|
| 569 |
+
| `category` | string | `all`, `arts_entertainment`, `health`, `sports`, etc. |
|
| 570 |
+
| `search_type` | string | `web`, `youtube`, `news`, `images`, `shopping` |
|
| 571 |
+
|
| 572 |
+
**Response:**
|
| 573 |
+
```json
|
| 574 |
+
{
|
| 575 |
+
"success": true,
|
| 576 |
+
"keyword": "weight loss",
|
| 577 |
+
"region": "US",
|
| 578 |
+
"timeframe": "today_12m",
|
| 579 |
+
"category": "health",
|
| 580 |
+
"search_type": "web",
|
| 581 |
+
"related_topics": {
|
| 582 |
+
"top": [{"topic": "Diet", "value": 100}],
|
| 583 |
+
"rising": [{"topic": "Ozempic", "value": 5000}]
|
| 584 |
+
},
|
| 585 |
+
"related_queries": {
|
| 586 |
+
"top": [{"query": "best diet for weight loss", "value": "100"}],
|
| 587 |
+
"rising": [{"query": "semaglutide weight loss", "value": "2400%"}]
|
| 588 |
+
}
|
| 589 |
+
}
|
| 590 |
+
```
|
| 591 |
+
|
| 592 |
+
---
|
| 593 |
+
|
| 594 |
+
### πΊ POST `/api/trends/youtube-trends` - YouTube Trends
|
| 595 |
+
|
| 596 |
+
**Request Body:**
|
| 597 |
+
```json
|
| 598 |
+
{
|
| 599 |
+
"keyword": "coding tutorial",
|
| 600 |
+
"region": "US",
|
| 601 |
+
"timeframe": "today_12m"
|
| 602 |
+
}
|
| 603 |
+
```
|
| 604 |
+
|
| 605 |
+
---
|
| 606 |
+
|
| 607 |
+
### π GET `/api/trends/categories` - List Categories
|
| 608 |
+
|
| 609 |
+
### π GET `/api/trends/countries` - List Countries
|
| 610 |
+
|
| 611 |
+
---
|
| 612 |
+
|
| 613 |
+
## 7. Common Patterns
|
| 614 |
+
|
| 615 |
+
### Status Polling Pattern
|
| 616 |
+
|
| 617 |
+
All video generation endpoints follow this pattern:
|
| 618 |
+
|
| 619 |
+
```
|
| 620 |
+
1. POST /create β Returns job_id
|
| 621 |
+
2. GET /status β Poll until status = "ready"
|
| 622 |
+
3. GET /download β Get video file
|
| 623 |
+
```
|
| 624 |
+
|
| 625 |
+
**Python Example:**
|
| 626 |
+
```python
|
| 627 |
+
import requests
|
| 628 |
+
import time
|
| 629 |
+
|
| 630 |
+
# 1. Create video
|
| 631 |
+
response = requests.post(
|
| 632 |
+
"https://your-space.hf.space/api/short-video",
|
| 633 |
+
json={
|
| 634 |
+
"scenes": [{"text": "Hello world", "searchTerms": ["nature"]}],
|
| 635 |
+
"config": {"voice": "af_heart"}
|
| 636 |
+
}
|
| 637 |
+
)
|
| 638 |
+
video_id = response.json()["videoId"]
|
| 639 |
+
|
| 640 |
+
# 2. Poll status
|
| 641 |
+
while True:
|
| 642 |
+
status = requests.get(f"https://your-space.hf.space/api/short-video/{video_id}/status").json()
|
| 643 |
+
if status["status"] == "ready":
|
| 644 |
+
break
|
| 645 |
+
elif status["status"] == "failed":
|
| 646 |
+
raise Exception("Video generation failed")
|
| 647 |
+
time.sleep(5)
|
| 648 |
+
|
| 649 |
+
# 3. Download video
|
| 650 |
+
video = requests.get(f"https://your-space.hf.space/api/short-video/{video_id}")
|
| 651 |
+
with open("output.mp4", "wb") as f:
|
| 652 |
+
f.write(video.content)
|
| 653 |
+
```
|
| 654 |
+
|
| 655 |
+
---
|
| 656 |
+
|
| 657 |
+
## 8. HF Cloud Storage & Download
|
| 658 |
+
|
| 659 |
+
Videos are automatically uploaded to Hugging Face Dataset when `HF_REPO` and `HF_TOKEN` are configured. Here's how to get the download URL:
|
| 660 |
+
|
| 661 |
+
---
|
| 662 |
+
|
| 663 |
+
### π₯ Method 1: Get URL from Status Response
|
| 664 |
+
|
| 665 |
+
When video is ready, `video_url` field contains the direct cloud URL:
|
| 666 |
+
|
| 667 |
+
```python
|
| 668 |
+
import requests
|
| 669 |
+
import time
|
| 670 |
+
|
| 671 |
+
BASE_URL = "https://your-space.hf.space"
|
| 672 |
+
job_id = "abc123"
|
| 673 |
+
|
| 674 |
+
# Poll until ready
|
| 675 |
+
while True:
|
| 676 |
+
response = requests.get(f"{BASE_URL}/api/story-reel/{job_id}/status")
|
| 677 |
+
data = response.json()
|
| 678 |
+
|
| 679 |
+
if data["status"] == "ready":
|
| 680 |
+
# β
Cloud URL is in video_url field!
|
| 681 |
+
cloud_url = data["video_url"]
|
| 682 |
+
print(f"Download URL: {cloud_url}")
|
| 683 |
+
# Output: https://huggingface.co/datasets/username/repo/resolve/main/story_reels/abc123.mp4?download=true
|
| 684 |
+
break
|
| 685 |
+
elif data["status"] == "failed":
|
| 686 |
+
print(f"Error: {data.get('error')}")
|
| 687 |
+
break
|
| 688 |
+
|
| 689 |
+
time.sleep(3)
|
| 690 |
+
```
|
| 691 |
+
|
| 692 |
+
**Status Response with Cloud URL:**
|
| 693 |
+
```json
|
| 694 |
+
{
|
| 695 |
+
"job_id": "abc123",
|
| 696 |
+
"status": "ready",
|
| 697 |
+
"progress": 100,
|
| 698 |
+
"video_url": "https://huggingface.co/datasets/username/repo/resolve/main/story_reels/abc123.mp4?download=true",
|
| 699 |
+
"error": null
|
| 700 |
+
}
|
| 701 |
+
```
|
| 702 |
+
|
| 703 |
+
---
|
| 704 |
+
|
| 705 |
+
### π₯ Method 2: Download Endpoint Auto-Redirect
|
| 706 |
+
|
| 707 |
+
The download endpoint automatically redirects to HF Hub URL:
|
| 708 |
+
|
| 709 |
+
```python
|
| 710 |
+
# Download endpoint auto-redirects to cloud
|
| 711 |
+
response = requests.get(
|
| 712 |
+
f"{BASE_URL}/api/story-reel/{job_id}",
|
| 713 |
+
allow_redirects=True # Default
|
| 714 |
+
)
|
| 715 |
+
|
| 716 |
+
# Get the final URL after redirect
|
| 717 |
+
final_url = response.url
|
| 718 |
+
print(f"Final URL: {final_url}")
|
| 719 |
+
# Output: https://huggingface.co/datasets/...
|
| 720 |
+
|
| 721 |
+
# Or get redirect URL without following
|
| 722 |
+
response = requests.get(
|
| 723 |
+
f"{BASE_URL}/api/story-reel/{job_id}",
|
| 724 |
+
allow_redirects=False
|
| 725 |
+
)
|
| 726 |
+
if response.status_code == 302:
|
| 727 |
+
cloud_url = response.headers["Location"]
|
| 728 |
+
```
|
| 729 |
+
|
| 730 |
+
---
|
| 731 |
+
|
| 732 |
+
### π Module Support Matrix
|
| 733 |
+
|
| 734 |
+
| Module | Status Endpoint | `video_url` in Status | Auto-Redirect |
|
| 735 |
+
|--------|----------------|----------------------|---------------|
|
| 736 |
+
| Story Reels | `/api/story-reel/{id}/status` | β
Yes | β
Yes |
|
| 737 |
+
| Fact Image | `/api/fact-image/{id}/status` | β
Yes | β
Yes |
|
| 738 |
+
| Quiz Reel | `/api/quiz/{id}/status` | β
Yes | β
Yes |
|
| 739 |
+
| Text Story | `/api/text-story/{id}/status` | β
Yes | β
Yes |
|
| 740 |
+
| Video Creator | `/api/short-video/{id}/status` | β No | β
Yes |
|
| 741 |
+
|
| 742 |
+
---
|
| 743 |
+
|
| 744 |
+
### π Cloud URL Format
|
| 745 |
+
|
| 746 |
+
```
|
| 747 |
+
https://huggingface.co/datasets/{HF_REPO}/resolve/main/{folder}/{video_id}.mp4?download=true
|
| 748 |
+
```
|
| 749 |
+
|
| 750 |
+
**Folders by Module:**
|
| 751 |
+
| Module | Folder |
|
| 752 |
+
|--------|--------|
|
| 753 |
+
| Video Creator | `short_video` |
|
| 754 |
+
| Story Reels | `story_reels` |
|
| 755 |
+
| Fact Image | `fact_image` |
|
| 756 |
+
| Quiz Reel | `quiz_reel` |
|
| 757 |
+
| Text Story | `text_story` |
|
| 758 |
+
|
| 759 |
+
---
|
| 760 |
+
|
| 761 |
+
### β‘ Complete Python Example
|
| 762 |
+
|
| 763 |
+
```python
|
| 764 |
+
import requests
|
| 765 |
+
import time
|
| 766 |
+
|
| 767 |
+
def create_and_download_video(base_url, script, voice="af_heart"):
|
| 768 |
+
"""
|
| 769 |
+
Complete workflow: Create β Poll β Get Cloud URL
|
| 770 |
+
"""
|
| 771 |
+
|
| 772 |
+
# 1. Create video
|
| 773 |
+
response = requests.post(
|
| 774 |
+
f"{base_url}/api/story-reel",
|
| 775 |
+
json={
|
| 776 |
+
"script": script,
|
| 777 |
+
"voice": voice,
|
| 778 |
+
"image_style": "semi-realistic"
|
| 779 |
+
}
|
| 780 |
+
)
|
| 781 |
+
job_id = response.json()["job_id"]
|
| 782 |
+
print(f"Job created: {job_id}")
|
| 783 |
+
|
| 784 |
+
# 2. Poll status until ready
|
| 785 |
+
while True:
|
| 786 |
+
status_resp = requests.get(f"{base_url}/api/story-reel/{job_id}/status")
|
| 787 |
+
status = status_resp.json()
|
| 788 |
+
|
| 789 |
+
print(f"Status: {status['status']} | Progress: {status.get('progress', 0)}%")
|
| 790 |
+
|
| 791 |
+
if status["status"] == "ready":
|
| 792 |
+
# 3. Get cloud URL from status response
|
| 793 |
+
cloud_url = status["video_url"]
|
| 794 |
+
print(f"\nβ
Video Ready!")
|
| 795 |
+
print(f"Cloud URL: {cloud_url}")
|
| 796 |
+
return cloud_url
|
| 797 |
+
|
| 798 |
+
elif status["status"] == "failed":
|
| 799 |
+
raise Exception(f"Failed: {status.get('error')}")
|
| 800 |
+
|
| 801 |
+
time.sleep(5)
|
| 802 |
+
|
| 803 |
+
|
| 804 |
+
# Usage
|
| 805 |
+
cloud_url = create_and_download_video(
|
| 806 |
+
base_url="https://your-space.hf.space",
|
| 807 |
+
script="Once upon a time in a magical forest..."
|
| 808 |
+
)
|
| 809 |
+
|
| 810 |
+
# Download to file
|
| 811 |
+
video = requests.get(cloud_url)
|
| 812 |
+
with open("output.mp4", "wb") as f:
|
| 813 |
+
f.write(video.content)
|
| 814 |
+
```
|
| 815 |
+
|
| 816 |
+
---
|
| 817 |
+
|
| 818 |
+
## 9. Environment Variables
|
| 819 |
+
|
| 820 |
+
Configure these in your HF Space secrets or `.env` file:
|
| 821 |
+
|
| 822 |
+
| Variable | Required | Description |
|
| 823 |
+
|----------|----------|-------------|
|
| 824 |
+
| `HF_TTS` | β
| Kokoro TTS API URL |
|
| 825 |
+
| `PEXELS_API` | β | Pexels API key for stock videos |
|
| 826 |
+
| `PIXABAY_API` | β | Pixabay API key for stock videos |
|
| 827 |
+
| `NVIDIA_API` | β | NVIDIA Cosmos API key for AI images |
|
| 828 |
+
| `CLOUDFLARE_API` | β | Cloudflare AI API key |
|
| 829 |
+
| `GROQ_API` | β | Groq API key for AI text generation |
|
| 830 |
+
| `HF_REPO` | β | HF Dataset repo for cloud storage |
|
| 831 |
+
| `HF_TOKEN` | β | HF token with write access |
|
| 832 |
+
|
| 833 |
+
---
|
| 834 |
+
|
| 835 |
+
## Voice Options
|
| 836 |
+
|
| 837 |
+
### Female Voices (af_)
|
| 838 |
+
- `af_heart` β - Warm, engaging
|
| 839 |
+
- `af_bella` - Soft, natural
|
| 840 |
+
- `af_sarah` - Clear, professional
|
| 841 |
+
- `af_nova` - Energetic
|
| 842 |
+
- `af_sky` - Youthful
|
| 843 |
+
|
| 844 |
+
### Male Voices (am_)
|
| 845 |
+
- `am_adam` - Deep, authoritative
|
| 846 |
+
- `am_fenrir` β - Natural, conversational
|
| 847 |
+
- `am_michael` - Clear, professional
|
| 848 |
+
- `am_liam` - Friendly
|
| 849 |
+
|
| 850 |
+
### British Voices (bf_, bm_)
|
| 851 |
+
- `bf_emma` - British female
|
| 852 |
+
- `bm_george` - British male
|
| 853 |
+
|
| 854 |
+
---
|
| 855 |
+
|
| 856 |
+
## Error Handling
|
| 857 |
+
|
| 858 |
+
All endpoints return standard HTTP error codes:
|
| 859 |
+
|
| 860 |
+
| Code | Description |
|
| 861 |
+
|------|-------------|
|
| 862 |
+
| `400` | Bad request (validation error) |
|
| 863 |
+
| `404` | Resource not found |
|
| 864 |
+
| `500` | Internal server error |
|
| 865 |
+
| `503` | Service not initialized |
|
| 866 |
+
|
| 867 |
+
**Error Response Format:**
|
| 868 |
+
```json
|
| 869 |
+
{
|
| 870 |
+
"detail": "Error message here"
|
| 871 |
+
}
|
| 872 |
+
```
|
| 873 |
+
|
| 874 |
+
---
|
| 875 |
+
|
| 876 |
+
## Interactive API Docs
|
| 877 |
+
|
| 878 |
+
FastAPI provides automatic interactive documentation:
|
| 879 |
+
|
| 880 |
+
- **Swagger UI:** `https://YOUR-SPACE.hf.space/docs`
|
| 881 |
+
- **ReDoc:** `https://YOUR-SPACE.hf.space/redoc`
|
| 882 |
+
|
| 883 |
+
---
|
| 884 |
+
|
| 885 |
+
*Last Updated: December 2024*
|