Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,40 +58,44 @@ edit_pipe = LongCatImageEditPipeline.from_pretrained(
|
|
| 58 |
edit_pipe.to(device, torch.bfloat16)
|
| 59 |
|
| 60 |
print(f"✅ Image Edit model loaded successfully on {device}")
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
#
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
#
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
#
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
@spaces.GPU(duration=120)
|
| 97 |
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=4, num_inference_steps=28, lora_id=None, lora_scale=0.95, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 58 |
edit_pipe.to(device, torch.bfloat16)
|
| 59 |
|
| 60 |
print(f"✅ Image Edit model loaded successfully on {device}")
|
| 61 |
+
def load_lora_auto(pipe, lora_input):
|
| 62 |
+
lora_input = lora_input.strip()
|
| 63 |
+
if not lora_input:
|
| 64 |
+
return
|
| 65 |
+
|
| 66 |
+
# If it's just an ID like "author/model"
|
| 67 |
+
if "/" in lora_input and not lora_input.startswith("http"):
|
| 68 |
+
pipe.load_lora_weights(lora_input)
|
| 69 |
+
return
|
| 70 |
+
|
| 71 |
+
if lora_input.startswith("http"):
|
| 72 |
+
url = lora_input
|
| 73 |
+
|
| 74 |
+
# Repo page (no blob/resolve)
|
| 75 |
+
if "huggingface.co" in url and "/blob/" not in url and "/resolve/" not in url:
|
| 76 |
+
repo_id = urlparse(url).path.strip("/")
|
| 77 |
+
pipe.load_lora_weights(repo_id)
|
| 78 |
+
return
|
| 79 |
+
|
| 80 |
+
# Blob link → convert to resolve link
|
| 81 |
+
if "/blob/" in url:
|
| 82 |
+
url = url.replace("/blob/", "/resolve/")
|
| 83 |
+
|
| 84 |
+
# Download direct file
|
| 85 |
+
tmp_dir = tempfile.mkdtemp()
|
| 86 |
+
local_path = os.path.join(tmp_dir, os.path.basename(urlparse(url).path))
|
| 87 |
+
|
| 88 |
+
try:
|
| 89 |
+
print(f"Downloading LoRA from {url}...")
|
| 90 |
+
resp = requests.get(url, stream=True)
|
| 91 |
+
resp.raise_for_status()
|
| 92 |
+
with open(local_path, "wb") as f:
|
| 93 |
+
for chunk in resp.iter_content(chunk_size=8192):
|
| 94 |
+
f.write(chunk)
|
| 95 |
+
print(f"Saved LoRA to {local_path}")
|
| 96 |
+
pipe.load_lora_weights(local_path)
|
| 97 |
+
finally:
|
| 98 |
+
shutil.rmtree(tmp_dir, ignore_errors=True)
|
| 99 |
|
| 100 |
@spaces.GPU(duration=120)
|
| 101 |
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=4, num_inference_steps=28, lora_id=None, lora_scale=0.95, progress=gr.Progress(track_tqdm=True)):
|