File size: 6,092 Bytes
d37ebe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# Video Generation Endpoint API (Custom Handler)

This repository is configured for deployment as a **Hugging Face Inference Endpoint** using a **custom `handler.py`**. The endpoint generates a short video from a text prompt and can return the result as:

- **GIF** (preview-friendly)
- **WebM** (higher quality, better compression)
- **ZIP of PNG frames** (maximum control / post-processing)

---

## Endpoint URL

After deployment, your endpoint will look like:

```
https://<your-endpoint>.aws.endpoints.huggingface.cloud
```

Example:

```
https://cyjm1rsdzy6la31w.us-east-1.aws.endpoints.huggingface.cloud
```

---

## Authentication

All requests require a Hugging Face token with permission to call the endpoint.

Send it as a Bearer token:

```
Authorization: Bearer YOUR_HF_TOKEN
```

---

## Request Format

Hugging Face endpoint requests should be wrapped in a top-level `inputs` object:

```json
{
  "inputs": {
    "prompt": "cinematic sunset over mountains",
    "outputs": ["gif"]
  }
}
```

### Core Fields

| Field | Type | Default | Description |
|------|------|---------|-------------|
| `prompt` | string | **required** | Text prompt describing the video. |
| `negative_prompt` | string | `""` | Things you want to avoid. |
| `num_frames` | int | `32` | Number of frames to generate. |
| `fps` | int | `12` | Playback FPS for GIF/WebM (may be overridden per output). |
| `height` | int | `512` | Frame height. |
| `width` | int | `512` | Frame width. |
| `seed` | int | `null` | Seed for reproducibility. |
| `outputs` | array | `["gif"]` | Any subset: `["gif","webm","zip"]`. |
| `return_base64` | bool | `true` | If true, returns file contents as base64 strings. |
| `num_inference_steps` | int | `30` | More steps can improve quality but increases latency. |
| `guidance_scale` | float | `7.5` | Prompt adherence strength (higher = more literal). |

---

## Output Configuration

You can optionally include per-output options inside `inputs`.

### GIF options

```json
"gif": { "fps": 10 }
```

### WebM options

```json
"webm": { "fps": 24, "quality": "good" }
```

Quality values:

- `"fast"` — fastest encode
- `"good"` — balanced (recommended)
- `"best"` — higher quality, slower encode

### ZIP output

ZIP output contains PNG frames:

```
frame_000000.png
frame_000001.png
...
```

---

## Response Format

The handler returns JSON. On success:

```json
{
  "ok": true,
  "outputs": {
    "gif_base64": "...",
    "webm_base64": "...",
    "zip_base64": "..."
  },
  "diagnostics": {
    "timing_ms": { ... },
    "generator": { ... }
  }
}
```

On error:

```json
{
  "ok": false,
  "error": "human readable error message",
  "diagnostics": { ... }
}
```

---

## Example curl Commands (Direct-to-file)

These examples download **only the file** (decoded from base64 in the JSON response) without saving the JSON to disk.

> **Important:** We use `jq -er` so the command fails if the output key is missing. This prevents writing corrupted files when the API returns an error.

Replace `YOUR_HF_TOKEN` and your endpoint URL as needed.

---

### 1) GIF → `output.gif`

```bash
curl -sS -X POST "https://cyjm1rsdzy6la31w.us-east-1.aws.endpoints.huggingface.cloud" \
  -H "Authorization: Bearer YOUR_HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": {
      "prompt": "cinematic sunset over mountains, slow pan",
      "num_frames": 20,
      "fps": 10,
      "outputs": ["gif"]
    }
  }' \
| jq -er '.outputs.gif_base64' \
| base64 --decode > output.gif
```

---

### 2) WebM → `output.webm`

```bash
curl -sS -X POST "https://cyjm1rsdzy6la31w.us-east-1.aws.endpoints.huggingface.cloud" \
  -H "Authorization: Bearer YOUR_HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": {
      "prompt": "a drone flying through clouds, volumetric lighting",
      "num_frames": 32,
      "fps": 24,
      "outputs": ["webm"],
      "webm": { "quality": "good" }
    }
  }' \
| jq -er '.outputs.webm_base64' \
| base64 --decode > output.webm
```

---

### 3) ZIP (frames) → `frames.zip`

```bash
curl -sS -X POST "https://cyjm1rsdzy6la31w.us-east-1.aws.endpoints.huggingface.cloud" \
  -H "Authorization: Bearer YOUR_HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": {
      "prompt": "ocean waves crashing in slow motion",
      "num_frames": 16,
      "outputs": ["zip"]
    }
  }' \
| jq -er '.outputs.zip_base64' \
| base64 --decode > frames.zip
```

Unzip frames:

```bash
unzip frames.zip
```

---

### 4) Multi-output (GIF + WebM + ZIP)

```bash
curl -sS -X POST "https://cyjm1rsdzy6la31w.us-east-1.aws.endpoints.huggingface.cloud" \
  -H "Authorization: Bearer YOUR_HF_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": {
      "prompt": "epic cinematic space nebula, slow parallax motion",
      "num_frames": 24,
      "fps": 12,
      "outputs": ["gif", "webm", "zip"],
      "gif":  { "fps": 10 },
      "webm": { "fps": 24, "quality": "good" }
    }
  }' \
  -o response.json
```

Extract:

```bash
jq -er '.outputs.gif_base64'  response.json | base64 --decode > output.gif
jq -er '.outputs.webm_base64' response.json | base64 --decode > output.webm
jq -er '.outputs.zip_base64'  response.json | base64 --decode > frames.zip
```

---

## Troubleshooting

### “Corrupted” output files

Inspect the JSON first:

```bash
jq . response.json
```

Ensure:

```
"ok": true
```

### Large outputs

Reduce:

- `num_frames`
- `height` / `width`

Or modify the handler to upload to cloud storage and return a download URL.

---

## Repository Notes

This repo is designed for Hugging Face Inference Endpoints with a custom handler.

Key files:

- `handler.py` — request parsing, model invocation, output encoding
- `requirements.txt` — Python dependencies

If your model lives in a subdirectory, set the environment variable:

```
HF_MODEL_SUBDIR
```

---

## Security Notes

- Do not commit secrets or tokens into this repository.
- Use Endpoint Secrets / Environment Variables for credentials.

---

## License

Specify your license here (e.g., MIT, Apache-2.0).