Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from diffusers import QwenImageEditPlusPipeline
|
| 5 |
+
|
| 6 |
+
MODEL_ID = "Qwen/Qwen-Image-Edit-2509"
|
| 7 |
+
LORA_REPO = "lovis93/next-scene-qwen-image-lora-2509"
|
| 8 |
+
LORA_FILE = "next-scene_lora_v1-3000.safetensors"
|
| 9 |
+
|
| 10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
+
dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
|
| 12 |
+
|
| 13 |
+
pipe = QwenImageEditPlusPipeline.from_pretrained(MODEL_ID, torch_dtype=dtype).to(device)
|
| 14 |
+
pipe.load_lora_weights(LORA_REPO, weight_name=LORA_FILE)
|
| 15 |
+
|
| 16 |
+
def next_scene(image, prompt, steps, true_cfg_scale, lora_strength, seed):
|
| 17 |
+
gen = None
|
| 18 |
+
if seed and int(seed) != 0:
|
| 19 |
+
gen = torch.Generator(device=device).manual_seed(int(seed))
|
| 20 |
+
try:
|
| 21 |
+
pipe.set_adapters(["default"], adapter_weights=[float(lora_strength)])
|
| 22 |
+
except Exception:
|
| 23 |
+
pass
|
| 24 |
+
|
| 25 |
+
kwargs = dict(
|
| 26 |
+
image=[image],
|
| 27 |
+
prompt=prompt,
|
| 28 |
+
num_inference_steps=int(steps),
|
| 29 |
+
guidance_scale=1.0,
|
| 30 |
+
generator=gen,
|
| 31 |
+
)
|
| 32 |
+
try:
|
| 33 |
+
kwargs["true_cfg_scale"] = float(true_cfg_scale)
|
| 34 |
+
except Exception:
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
out = pipe(**kwargs)
|
| 38 |
+
return out.images[0]
|
| 39 |
+
|
| 40 |
+
with gr.Blocks() as demo:
|
| 41 |
+
gr.Markdown("## Next Scene — Qwen-Image-Edit-2509 + LoRA")
|
| 42 |
+
with gr.Row():
|
| 43 |
+
with gr.Column():
|
| 44 |
+
inp_img = gr.Image(type="pil", label="Входной кадр (старт сцены)")
|
| 45 |
+
prompt = gr.Textbox(
|
| 46 |
+
label='Промпт (начинайте с "Next Scene: ...")',
|
| 47 |
+
value='Next Scene: camera pulls back revealing the riverside at sunset, soft rim light, subtle lens flare.'
|
| 48 |
+
)
|
| 49 |
+
steps = gr.Slider(4, 60, value=40, step=1, label="Steps")
|
| 50 |
+
true_cfg = gr.Slider(1.0, 6.0, value=3.0, step=0.5, label="true_cfg_scale")
|
| 51 |
+
lora_strength = gr.Slider(0.0, 1.2, value=0.75, step=0.05, label="LoRA strength")
|
| 52 |
+
seed = gr.Number(value=0, label="Seed (0 = random)")
|
| 53 |
+
btn = gr.Button("Сгенерировать следующий кадр")
|
| 54 |
+
with gr.Column():
|
| 55 |
+
out_img = gr.Image(label="Результат")
|
| 56 |
+
|
| 57 |
+
btn.click(next_scene, [inp_img, prompt, steps, true_cfg, lora_strength, seed], [out_img])
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|