Spaces:
Sleeping
Sleeping
Update app.py
Browse files123456478910116121314151016171819132021222317242526277 unmodified lines353637313839404142433744454647# 1. ALWAYS IMPORT SPACES ABSOLUTELY FIRSTimport spaces import osimport torchfrom diffusers import DiffusionPipelineimport gradio as grimport spaces
# 2. Authenticate using the built-in Hugging Face Space Token# Ensure your Space has access to FLUX.1-dev on Hugging FaceHF_TOKEN = os.getenv("HF_TOKEN")
# 1. Initialize the base pipeline on CPU to save Zero GPU resources initially# 3. Initialize the base pipeline on CPU to save Zero GPU resources initiallymodel_id = "black-forest-labs/FLUX.1-dev"pipe = DiffusionPipeline.from_pretrained( model_id, torch_dtype=torch.bfloat16 torch_dtype=torch.bfloat16, token=HF_TOKEN)
# 2. Fuse the Icon Kit LoRA into the base model weights# 4. Fuse the Icon Kit LoRA into the base model weightspipe.load_lora_weights("strangerzonehf/Flux-Icon-Kit-LoRA")pipe.fuse_lora()
# 3. Create the execution wrapper explicitly decorated for Zero GPU allocation# 5. Create the execution wrapper explicitly decorated for Zero GPU allocation@spaces.GPU(duration=60) # Allocates dynamic GPU ceiling for up to 60 secondsdef generate_icon(prompt, num_inference_steps=28, guidance_scale=3.5): # Move the pipeline to the allocated GPU device safely7 unmodified lines prompt=full_prompt, num_inference_steps=int(num_inference_steps), guidance_scale=float(guidance_scale) ).images[0] ).images[0] # Extracted the exact PIL image from the list # Offload back to CPU to cleanly yield the Zero GPU slot back to the public pool pipe.to("cpu") return image
# 4. Expose the generation function as a clean Gradio API interface# 6. Expose the generation function as a clean Gradio API interfacedemo = gr.Interface( fn=generate_icon, inputs=[app.py+14-7