pdbdb commited on
Commit
5947edc
Β·
1 Parent(s): e1f601c

first test

Browse files
Files changed (2) hide show
  1. app.py +64 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr, torch, uuid
2
+ from pathlib import Path
3
+ from diffusers import StableDiffusionXLPipeline
4
+
5
+ # Hub IDs of the weights you just pushed
6
+ BASE_MODEL_REPO = "SG161222/RealVisXL_V5.0" # or a public ID
7
+ LORA_REPO = "pdbdb/lora-act"
8
+
9
+ print("⏳ Loading SDXL base …")
10
+ pipe = StableDiffusionXLPipeline.from_single_file(
11
+ BASE_MODEL_REPO,
12
+ torch_dtype=torch.float16,
13
+ variant="fp16",
14
+ add_watermarker=False,
15
+ ).to("cuda")
16
+
17
+ # ── collect LoRAs from the Hub snapshot ──────────────────────────
18
+ snapshot_path = Path(
19
+ torch.hub.download_url_to_file( # one-liner cache download
20
+ f"https://huggingface.co/{LORA_REPO}/resolve/main/.gitattributes",
21
+ "tmp") # dummy target; we only need the snapshot
22
+ ).parent
23
+ LORA_MAP = {"none": None}
24
+ for p in snapshot_path.glob("**/*.safetensors"):
25
+ LORA_MAP[p.name] = str(p)
26
+ LORA_LABELS = list(LORA_MAP.keys())
27
+
28
+ NEG_PROMPT = "out of frame, lowres, text, error, cropped, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, username, watermark, signature"
29
+
30
+ @torch.inference_mode()
31
+ def generate(prompt, lora_label, lora_weight, guidance, steps, seed):
32
+ torch.cuda.empty_cache()
33
+ pipe.unload_lora_weights()
34
+
35
+ if lora_label != "none":
36
+ pipe.load_lora_weights(
37
+ LORA_MAP[lora_label],
38
+ weight=float(lora_weight),
39
+ adapter_name=f"live_{uuid.uuid4().hex[:6]}",
40
+ )
41
+
42
+ g = torch.Generator("cuda").manual_seed(int(seed))
43
+ img = pipe(prompt,
44
+ negative_prompt=NEG_PROMPT,
45
+ num_inference_steps=int(steps),
46
+ guidance_scale=float(guidance),
47
+ generator=g).images[0]
48
+ return img
49
+
50
+ with gr.Blocks() as demo:
51
+ gr.Markdown("## SDXL LoRA Playground")
52
+ with gr.Row():
53
+ prompt = gr.Textbox(label="Prompt", scale=4)
54
+ run_btn = gr.Button("Generate", variant="primary")
55
+ with gr.Row():
56
+ lora = gr.Dropdown(label="LoRA checkpoint", choices=LORA_LABELS, value="none")
57
+ weight = gr.Slider(0, 1.2, 1.0, 0.05, label="LoRA weight")
58
+ guide = gr.Slider(2, 15, 6.5, 0.5, label="Guidance scale")
59
+ steps = gr.Slider(20, 60, 40, 5, label="Steps")
60
+ seed = gr.Number(42, label="Seed", precision=0)
61
+ out = gr.Image(height=512)
62
+ run_btn.click(generate, [prompt, lora, weight, guide, steps, seed], out)
63
+
64
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ diffusers==0.29.0
2
+ transformers>=4.41.0
3
+ accelerate>=0.29.0
4
+ safetensors
5
+ xformers
6
+ torch>=2.3,<2.7 # 2.6.0 wheels are not on HF yet
7
+ gradio>=4.34