Skip to content

Commit 38d1ee3

Browse files
uzunenescursoragent
andcommitted
docs: all example outputs in sample_outputs; wait for video, show in READMEs
- fetch_sample_outputs: 02/03/07/08 images + 04 video with poll loop (no skip) - sample_outputs: generate_unified, cache_demo, semantic_exact, semantic_similar + existing 3 - examples/README: Result previews table with all images - README: sample outputs table + link to examples/README for full previews - sample_outputs/README: full file list by example Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b15d0a2 commit 38d1ee3

11 files changed

Lines changed: 148 additions & 53 deletions

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,21 @@ See the [`examples/`](examples/) directory for tested scripts covering every SDK
216216
VISGATE_API_KEY=vg-... python examples/run_all_capabilities.py
217217
```
218218

219-
### Sample outputs (image & video)
219+
### Sample outputs (all examples)
220220

221-
Example results from the API with curated prompts are under [`examples/sample_outputs/`](examples/sample_outputs/). You can regenerate them with:
221+
Example results (images and optional video) from each example are under [`examples/sample_outputs/`](examples/sample_outputs/). **Full previews** are in [examples/README.md](examples/README.md#sample-outputs). Regenerate (script waits for video, no skip):
222222

223223
```bash
224224
cd examples && python fetch_sample_outputs.py
225225
```
226226

227-
| Prompt | Output |
228-
|--------|--------|
229-
| Golden hour sunset over Istanbul Bosphorus... | ![Sunset Istanbul](examples/sample_outputs/sunset_istanbul.jpg) |
230-
| A fluffy orange cat astronaut in space... | ![Cat astronaut](examples/sample_outputs/cat_astronaut.jpg) |
231-
| Cappadocia hot air balloons at dawn... | ![Cappadocia](examples/sample_outputs/cappadocia_balloons.jpg) |
232-
233-
Video (async): run `fetch_sample_outputs.py` to generate a short beach-waves clip; the script saves it to `sample_outputs/beach_waves.mp4` when the URL is ready.
227+
| Example | Output |
228+
|---------|--------|
229+
| 02 generate_unified | ![generate_unified](examples/sample_outputs/generate_unified.jpg) |
230+
| 03 images | ![sunset_istanbul](examples/sample_outputs/sunset_istanbul.jpg) ![cat_astronaut](examples/sample_outputs/cat_astronaut.jpg) ![cappadocia](examples/sample_outputs/cappadocia_balloons.jpg) |
231+
| 07 cache_demo | ![cache_demo](examples/sample_outputs/cache_demo.jpg) |
232+
| 08 semantic | ![semantic_exact](examples/sample_outputs/semantic_exact.jpg) ![semantic_similar](examples/sample_outputs/semantic_similar.jpg) |
233+
| 04 video | `beach_waves.mp4` (async; script waits) |
234234

235235
## Contributing
236236

examples/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,24 @@ The first two steps run without an API key. `VISGATE_API_KEY` is required from s
4848

4949
## Sample outputs
5050

51-
Generated image (and optional video) samples with nice prompts are saved in [`sample_outputs/`](sample_outputs/). To regenerate them:
51+
All example outputs (images and optional video) are in [`sample_outputs/`](sample_outputs/). Regenerate with:
5252

5353
```bash
5454
cd examples
5555
python fetch_sample_outputs.py
5656
```
5757

58-
Requires `VISGATE_API_KEY` and optionally `VISGATE_FAL_API_KEY`. Outputs: `sunset_istanbul.jpg`, `cat_astronaut.jpg`, `cappadocia_balloons.jpg`, and optionally `beach_waves.mp4` (video may be async).
58+
The script waits for video when the API returns async (no skip). Requires `VISGATE_API_KEY`.
59+
60+
### Result previews (by example)
61+
62+
| Example | Output |
63+
|---------|--------|
64+
| **02** generate_unified | ![generate_unified](sample_outputs/generate_unified.jpg) |
65+
| **03** images (sunset_istanbul) | ![sunset_istanbul](sample_outputs/sunset_istanbul.jpg) |
66+
| **03** images (cat_astronaut) | ![cat_astronaut](sample_outputs/cat_astronaut.jpg) |
67+
| **03** images (cappadocia_balloons) | ![cappadocia_balloons](sample_outputs/cappadocia_balloons.jpg) |
68+
| **07** cache_demo | ![cache_demo](sample_outputs/cache_demo.jpg) |
69+
| **08** semantic_exact | ![semantic_exact](sample_outputs/semantic_exact.jpg) |
70+
| **08** semantic_similar | ![semantic_similar](sample_outputs/semantic_similar.jpg) |
71+
| **04** video | `beach_waves.mp4` (run script; video may be async) |

examples/fetch_sample_outputs.py

Lines changed: 113 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,44 @@
11
#!/usr/bin/env python3
22
"""
3-
Generate sample images (and optionally video) with nice prompts and save to
4-
examples/sample_outputs/. Run with VISGATE_API_KEY and optionally VISGATE_FAL_API_KEY.
3+
Generate sample outputs for all example types (images + video) and save to
4+
examples/sample_outputs/. Waits for video when async. Run with VISGATE_API_KEY.
55
66
cd examples && python fetch_sample_outputs.py
77
"""
88
from __future__ import annotations
99

10-
import os
1110
import sys
11+
import time
1212
from pathlib import Path
1313

1414
import httpx
1515

16-
# Add parent for _common
1716
sys.path.insert(0, str(Path(__file__).resolve().parent))
18-
1917
from _common import create_client
2018

2119
OUTPUT_DIR = Path(__file__).resolve().parent / "sample_outputs"
2220

21+
# 02_generate_unified
22+
GENERATE_PROMPT = "Istanbul skyline at sunset, realistic photo"
23+
24+
# 03_images_all_providers style
2325
IMAGE_PROMPTS = [
24-
("sunset_istanbul", "Golden hour sunset over Istanbul Bosphorus, minarets and seagulls, cinematic, detailed, 8k"),
25-
("cat_astronaut", "A fluffy orange cat astronaut floating in space, Earth in the background, photorealistic, whimsical"),
26-
("cappadocia_balloons", "Cinematic drone shot of Cappadocia hot air balloons at dawn, soft light, detailed landscape"),
26+
("sunset_istanbul", "Golden hour sunset over Istanbul Bosphorus, minarets and seagulls, cinematic, 8k"),
27+
("cat_astronaut", "A fluffy orange cat astronaut in space, Earth in background, photorealistic, whimsical"),
28+
("cappadocia_balloons", "Cappadocia hot air balloons at dawn, cinematic drone, soft light"),
2729
]
2830

31+
# 07_cache_demo
32+
CACHE_PROMPT = "A red apple on a wooden table, studio lighting"
33+
34+
# 08_semantic_cache_demo
35+
SEMANTIC_PROMPT_1 = "A red apple on a wooden table, studio lighting"
36+
SEMANTIC_PROMPT_2 = "Red apple on wooden table with studio lights"
37+
38+
# 04_videos
2939
VIDEO_PROMPT = ("beach_waves", "Waves crashing on a quiet beach at sunset, cinematic, 4k", 4.0)
40+
VIDEO_POLL_SLEEP = 25
41+
VIDEO_POLL_ATTEMPTS = 6
3042

3143

3244
def download_url(url: str, path: Path, timeout: float = 60.0) -> None:
@@ -40,42 +52,108 @@ def main() -> int:
4052
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
4153

4254
with create_client() as client:
43-
# Images
55+
# --- 02_generate_unified ---
56+
print("02 generate_unified ...")
57+
try:
58+
gen = client.generate(prompt=GENERATE_PROMPT, model="fal-ai/flux/schnell")
59+
if gen.images:
60+
path = OUTPUT_DIR / "generate_unified.jpg"
61+
download_url(gen.images[0], path)
62+
print(f" Saved {path}")
63+
except Exception as e:
64+
print(f" Skip: {e}")
65+
66+
# --- 03 images (nice prompts) ---
4467
for name, prompt in IMAGE_PROMPTS:
45-
print(f"Generating image: {name} ...")
46-
result = client.images.generate(
68+
print(f"03 image {name} ...")
69+
try:
70+
result = client.images.generate(
71+
model="fal-ai/flux/schnell",
72+
prompt=prompt,
73+
width=1024,
74+
height=1024,
75+
num_images=1,
76+
)
77+
if result.images:
78+
ext = ".png" if ".png" in result.images[0].split("?")[0].lower() else ".jpg"
79+
path = OUTPUT_DIR / f"{name}{ext}"
80+
download_url(result.images[0], path)
81+
print(f" Saved {path}")
82+
except Exception as e:
83+
print(f" Skip: {e}")
84+
85+
# --- 07_cache_demo (first request image) ---
86+
print("07 cache_demo (first request) ...")
87+
try:
88+
r1 = client.images.generate(
4789
model="fal-ai/flux/schnell",
48-
prompt=prompt,
90+
prompt=CACHE_PROMPT,
4991
width=1024,
5092
height=1024,
5193
num_images=1,
5294
)
53-
if not result.images:
54-
print(f" No image URL for {name}", file=sys.stderr)
55-
continue
56-
url = result.images[0]
57-
ext = ".png" if ".png" in url.split("?")[0].lower() else ".jpg"
58-
path = OUTPUT_DIR / f"{name}{ext}"
59-
download_url(url, path)
60-
print(f" Saved {path}")
61-
62-
# Video (one short clip)
63-
vname, vprompt, vdur = VIDEO_PROMPT
64-
print(f"Generating video: {vname} ...")
95+
if r1.images:
96+
path = OUTPUT_DIR / "cache_demo.jpg"
97+
download_url(r1.images[0], path)
98+
print(f" Saved {path}")
99+
except Exception as e:
100+
print(f" Skip: {e}")
101+
102+
# --- 08_semantic_cache_demo (exact + similar) ---
103+
print("08 semantic_exact ...")
65104
try:
66-
vresult = client.videos.generate(
67-
model="fal-ai/flux-pro/video",
68-
prompt=vprompt,
69-
duration_seconds=vdur,
105+
r1 = client.images.generate(
106+
model="fal-ai/flux/schnell",
107+
prompt=SEMANTIC_PROMPT_1,
108+
width=1024,
109+
height=1024,
110+
num_images=1,
111+
)
112+
if r1.images:
113+
path = OUTPUT_DIR / "semantic_exact.jpg"
114+
download_url(r1.images[0], path)
115+
print(f" Saved {path}")
116+
except Exception as e:
117+
print(f" Skip: {e}")
118+
119+
print("08 semantic_similar ...")
120+
try:
121+
r2 = client.images.generate(
122+
model="fal-ai/flux/schnell",
123+
prompt=SEMANTIC_PROMPT_2,
124+
width=1024,
125+
height=1024,
126+
num_images=1,
70127
)
71-
if vresult.video_url:
72-
vpath = OUTPUT_DIR / f"{vname}.mp4"
73-
download_url(vresult.video_url, vpath, timeout=120.0)
74-
print(f" Saved {vpath}")
75-
else:
76-
print(" Video URL not ready (async); skip download")
128+
if r2.images:
129+
path = OUTPUT_DIR / "semantic_similar.jpg"
130+
download_url(r2.images[0], path)
131+
print(f" Saved {path}")
77132
except Exception as e:
78-
print(f" Video skipped: {e}")
133+
print(f" Skip: {e}")
134+
135+
# --- 04 video: wait for result (poll by retrying) ---
136+
vname, vprompt, vdur = VIDEO_PROMPT
137+
print(f"04 video {vname} (waiting up to {VIDEO_POLL_ATTEMPTS * VIDEO_POLL_SLEEP}s) ...")
138+
for attempt in range(VIDEO_POLL_ATTEMPTS):
139+
try:
140+
vresult = client.videos.generate(
141+
model="fal-ai/flux-pro/video",
142+
prompt=vprompt,
143+
duration_seconds=vdur,
144+
)
145+
if vresult.video_url:
146+
vpath = OUTPUT_DIR / f"{vname}.mp4"
147+
download_url(vresult.video_url, vpath, timeout=120.0)
148+
print(f" Saved {vpath}")
149+
break
150+
except Exception as e:
151+
print(f" Attempt {attempt + 1}: {e}")
152+
if attempt < VIDEO_POLL_ATTEMPTS - 1:
153+
print(f" No URL yet, sleeping {VIDEO_POLL_SLEEP}s ...")
154+
time.sleep(VIDEO_POLL_SLEEP)
155+
else:
156+
print(" Video URL not ready after waiting; run script again later to fetch.")
79157

80158
print(f"\nSample outputs in {OUTPUT_DIR}")
81159
return 0

examples/sample_outputs/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Sample outputs
22

3-
Example images (and optionally video) generated with the Visgate API via `fetch_sample_outputs.py`.
3+
Example results from the SDK examples (images and optional video). Generated by `fetch_sample_outputs.py`; the script waits for video when the API returns async.
44

5-
| File | Prompt |
6-
|------|--------|
7-
| `sunset_istanbul.jpg` | Golden hour sunset over Istanbul Bosphorus, minarets and seagulls, cinematic, detailed, 8k |
8-
| `cat_astronaut.jpg` | A fluffy orange cat astronaut floating in space, Earth in the background, photorealistic, whimsical |
9-
| `cappadocia_balloons.jpg` | Cinematic drone shot of Cappadocia hot air balloons at dawn, soft light, detailed landscape |
10-
| `beach_waves.mp4` | Waves crashing on a quiet beach at sunset (async; run the script to generate when ready) |
5+
| Example | File | Prompt / description |
6+
|---------|------|----------------------|
7+
| **02** generate_unified | [generate_unified.jpg](generate_unified.jpg) | Istanbul skyline at sunset |
8+
| **03** images | [sunset_istanbul.jpg](sunset_istanbul.jpg) | Golden hour sunset over Istanbul Bosphorus |
9+
| **03** images | [cat_astronaut.jpg](cat_astronaut.jpg) | Cat astronaut in space |
10+
| **03** images | [cappadocia_balloons.jpg](cappadocia_balloons.jpg) | Cappadocia hot air balloons at dawn |
11+
| **07** cache_demo | [cache_demo.jpg](cache_demo.jpg) | Red apple on wooden table (first request) |
12+
| **08** semantic | [semantic_exact.jpg](semantic_exact.jpg) | Red apple, studio lighting (exact) |
13+
| **08** semantic | [semantic_similar.jpg](semantic_similar.jpg) | Red apple, studio lights (similar prompt) |
14+
| **04** video | beach_waves.mp4 | Waves on beach at sunset (async; run script to fetch when ready) |
1115

1216
Regenerate: from `examples/`, run `python fetch_sample_outputs.py` (requires `VISGATE_API_KEY`).
106 KB
Loading
-80.5 KB
Loading
50.7 KB
Loading
158 KB
Loading
147 KB
Loading
167 KB
Loading

0 commit comments

Comments
 (0)