Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819207 unmodified lines28293031323334353637383940import torchfrom diffusers import DiffusionPipelineimport gradio as grimport spaces# 1. 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)# 2. 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@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 linesprompt=full_prompt,num_inference_steps=int(num_inference_steps),guidance_scale=float(guidance_scale)).images[0]# Offload back to CPU to cleanly yield the Zero GPU slot back to the public poolpipe.to("cpu")return image# 4. Expose the generation function as a clean Gradio API interfacedemo = gr.Interface(fn=generate_icon,inputs=[1234567891011121314151617181920212223242526277 unmodified lines35363738394041424344454647# 1. ALWAYS IMPORT SPACES ABSOLUTELY FIRSTimport spacesimport osimport torchfrom diffusers import DiffusionPipelineimport gradio as gr# 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")# 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,token=HF_TOKEN)# 4. Fuse the Icon Kit LoRA into the base model weightspipe.load_lora_weights("strangerzonehf/Flux-Icon-Kit-LoRA")pipe.fuse_lora()# 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 linesprompt=full_prompt,num_inference_steps=int(num_inference_steps),guidance_scale=float(guidance_scale)).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 poolpipe.to("cpu")return image# 6. Expose the generation function as a clean Gradio API interfacedemo = gr.Interface(fn=generate_icon,inputs=[
app.py+14-7