Spaces:
Sleeping
Sleeping
adlib preview images: Z-Image Turbo on ZeroGPU (ADLIB_MODE=image)
Browse filesFiles changed (4)
- README.md+15-6
- __pycache__/app.cpython-310.pycAdded
- app.pyAdded+69
- requirements.txtAdded+9
12345678910111213---title: Adlib Preview Imageemoji: 📉colorFrom: indigocolorTo: graysdk: gradiosdk_version: 6.33.0python_version: '3.12'app_file: app.pypinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference12345678910111213141516171819202122---title: adlib previewemoji: 🎬colorFrom: yellowcolorTo: graysdk: gradioapp_file: app.pypinned: falselicense: apache-2.0short_description: Free preview shots for adlib (image and image-to-video)---# adlib preview SpaceThe free, preview-quality generator behind adlib's free mode. adlib calls two endpoints with the user's own Hugging Face token, so every call uses the caller's ZeroGPU quota, not the Space owner's:| Endpoint | Inputs | Output | Model || --- | --- | --- | --- || `/image` | prompt, aspect ratio (9:16, 16:9, 1:1, 4:5) | image | Z-Image Turbo by Alibaba Tongyi (Apache-2.0) || `/video` | prompt, start image, seconds (2 to 5) | video, 24 fps, up to 5 s | Wan 2.2 TI2V-5B (Apache-2.0) |Hardware: ZeroGPU. Both models allow commercial use of the generated images and videos.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869# adlib preview Space: free, preview-quality shots for adlib's free mode.# Runs on ZeroGPU; every call uses the CALLER's daily GPU quota (adlib sends# the user's own Hugging Face token). Endpoint names and input order are a# contract with adlib's catalog (huggingface-space/image and /video).import mathimport osimport tempfile
import gradio as grimport spacesimport torchfrom diffusers import ZImagePipeline, WanImageToVideoPipeline, AutoencoderKLWanfrom diffusers.utils import export_to_videofrom PIL import Image
IMAGE_MODEL = "Tongyi-MAI/Z-Image-Turbo" # Apache-2.0, not gatedVIDEO_MODEL = "Wan-AI/Wan2.2-TI2V-5B-Diffusers" # Apache-2.0
# One model per Space: both together do not fit the default ZeroGPU size# (48 GB). ADLIB_MODE is set per Space: "image" or "video".MODE = os.environ.get("ADLIB_MODE", "video")if MODE == "image": image_pipe = ZImagePipeline.from_pretrained(IMAGE_MODEL, torch_dtype=torch.bfloat16).to("cuda")else: vae = AutoencoderKLWan.from_pretrained(VIDEO_MODEL, subfolder="vae", torch_dtype=torch.float32) video_pipe = WanImageToVideoPipeline.from_pretrained(VIDEO_MODEL, vae=vae, torch_dtype=torch.bfloat16).to("cuda")
SIZES = {"9:16": (768, 1344), "16:9": (1344, 768), "1:1": (1024, 1024), "4:5": (896, 1120)}FPS = 24
@spaces.GPU(duration=30)def image(prompt: str, aspect: str): w, h = SIZES.get(aspect, SIZES["9:16"]) out = image_pipe(prompt=prompt, width=w, height=h, num_inference_steps=9, guidance_scale=0.0).images[0] # 8 DiT steps, no guidance (Turbo) path = tempfile.NamedTemporaryFile(suffix=".png", delete=False).name out.save(path) return path
@spaces.GPU(duration=150)def video(prompt: str, start: str, seconds: float): seconds = max(2.0, min(5.0, float(seconds or 5))) img = Image.open(start).convert("RGB") # Wan 2.2 TI2V-5B renders 720p: 1280x704 or 704x1280. w, h = (704, 1280) if img.height >= img.width else (1280, 704) img = img.resize((w, h)) frames = 4 * math.ceil(seconds * FPS / 4) + 1 # 4k+1 frames out = video_pipe(image=img, prompt=prompt, height=h, width=w, num_frames=frames, num_inference_steps=30, guidance_scale=5.0).frames[0] path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name export_to_video(out, path, fps=FPS) return path
with gr.Blocks(title="adlib preview") as demo: gr.Markdown("Free preview shots for adlib. Calls use your own ZeroGPU quota.") if MODE == "image": p1 = gr.Textbox(label="prompt") a1 = gr.Dropdown(list(SIZES), value="9:16", label="aspect") o1 = gr.Image(type="filepath") gr.Button("Generate").click(image, [p1, a1], o1, api_name="image") else: p2 = gr.Textbox(label="prompt") i2 = gr.Image(type="filepath", label="start image") s2 = gr.Number(value=5, label="seconds") o2 = gr.Video() gr.Button("Generate").click(video, [p2, i2, s2], o2, api_name="video")
demo.queue(default_concurrency_limit=1).launch()123456789torchdiffusers>=0.36.0transformersacceleratesentencepieceimageioimageio-ffmpegftfyspacesREADME.md+15-6
__pycache__/app.cpython-310.pycAdded
app.pyAdded+69
requirements.txtAdded+9