Spaces:
Sleeping
Sleeping
Update app.py
Browse files7 unmodified lines8910111213141516171819202122235 unmodified lines293031323334353637383940417 unmodified lines# 2. Retrieve token from space secretsHF_TOKEN = os.getenv("HF_TOKEN")# 3. Optimize the pipeline instantiation for severe CPU RAM limitsmodel_id = "black-forest-labs/FLUX.1-dev"pipe = DiffusionPipeline.from_pretrained(model_id,torch_dtype=torch.bfloat16, # Use half-precision for memory savingslow_cpu_mem_usage=True, # DO NOT load full weights into CPU system RAM at oncetoken=HF_TOKEN)# 4. Mount and fuse the LoRA weights cleanlypipe.load_lora_weights("strangerzonehf/Flux-Icon-Kit-LoRA")pipe.fuse_lora()5 unmodified linesfull_prompt = f"Icon Kit, {prompt}, minimalist UI UX design element, flat line icon, uniform stroke, solid background"image = pipe(prompt=full_prompt,num_inference_steps=int(num_inference_steps),guidance_scale=float(guidance_scale)).images[0] # Corrected syntax to safely extract the PIL object index# CRUCIAL: Immediately dump back to CPU so the container doesn't hang/crashpipe.to("cpu")return image7 unmodified lines8910111213141516171819202122235 unmodified lines29303132333435363738394041424344457 unmodified lines# 2. Retrieve token from space secretsHF_TOKEN = os.getenv("HF_TOKEN")# 3. Optimize the pipeline instantiation for RAM limitsmodel_id = "black-forest-labs/FLUX.1-dev"pipe = DiffusionPipeline.from_pretrained(model_id,torch_dtype=torch.bfloat16, # Use half-precision for memory savingslow_cpu_mem_usage=True, # Prevent loading full weights into CPU system RAM at oncetoken=HF_TOKEN)# 4. Mount and fuse the LoRA weights cleanly (Requires 'peft' in requirements.txt)pipe.load_lora_weights("strangerzonehf/Flux-Icon-Kit-LoRA")pipe.fuse_lora()5 unmodified linesfull_prompt = f"Icon Kit, {prompt}, minimalist UI UX design element, flat line icon, uniform stroke, solid background"# Run predictionoutput = pipe(prompt=full_prompt,num_inference_steps=int(num_inference_steps),guidance_scale=float(guidance_scale))# Extract the exact first PIL Image item from the output list safelyimage = output.images[0]# CRUCIAL: Immediately dump weights back to CPU to cleanly yield the Zero GPU slotpipe.to("cpu")return image
app.py+10-6