Download app.py from maryanlup/OT-RF: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/spaces/maryanlup/OT-RF/resolve/main/app.py
- Command line
-
hf download hf://spaces/maryanlup/OT-RF/app.py
-
curl -L -o app.py https://huggingface.co/spaces/maryanlup/OT-RF/resolve/main/app.py
2.04 kB
| import spaces | |
| import os, sys, torch | |
| import gradio as gr | |
| from diffusers import FluxPipeline | |
| from huggingface_hub import hf_hub_download | |
| base_pipe = FluxPipeline.from_pretrained( | |
| "black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16, | |
| custom_pipeline="pipeline_flux_rf_inversion") | |
| base_pipe.to("cuda") | |
| # Reuse the loaded RF-Inversion module so the OT file doesn't load FLUX a second time | |
| sys.modules["pipeline_flux_rf_inversion"] = sys.modules[type(base_pipe).__module__] | |
| sys.path.append(os.path.dirname(hf_hub_download("maryanlup/OT-RF", "improved_optimal_transport_rf_inversion.py"))) | |
| from improved_optimal_transport_rf_inversion import OptimalTransportRFInversionPipeline | |
| pipe = OptimalTransportRFInversionPipeline.from_pipe(base_pipe) | |
| def edit(image, prompt, stop_step, eta, seed): | |
| torch.manual_seed(int(seed)) | |
| image = image.convert("RGB").resize((1024, 1024)) | |
| inv, img_lat, ids = pipe.invert(image=image, num_inversion_steps=28) | |
| return pipe(prompt=prompt, inverted_latents=inv, image_latents=img_lat, | |
| latent_image_ids=ids, start_timestep=0, stop_timestep=stop_step / 28, | |
| num_inference_steps=28, eta=eta, use_ot_guidance=True, | |
| transport_strength=0.3, ot_guidance_phase=0.3, | |
| respect_prompt_guidance=False).images[0] | |
| gr.Interface( | |
| fn=edit, | |
| inputs=[gr.Image(type="pil", label="Input image"), | |
| gr.Textbox(value="a sleeping cat", label="Edit prompt"), | |
| gr.Slider(1, 28, value=7, step=1, label="Guidance stop step"), | |
| gr.Slider(0, 1, value=0.9, step=0.05, label="eta"), | |
| gr.Number(value=42, label="Seed")], | |
| outputs=gr.Image(label="Edited image"), | |
| title="Optimal Transport for Rectified Flow Image Editing (WACV 2026)", | |
| description="[Paper](https://huggingface.co/papers/2508.02363) 路 [Code](https://github.com/marianlupascu/OT-RF) 路 [Video](https://www.youtube.com/watch?v=ceJxfEnBIxQ) 路 [Poster](https://wacv.thecvf.com/virtual/2026/poster/955)", | |
| ).launch() |