MathObsession commited on
Commit
82a1c4d
·
verified ·
1 Parent(s): 1f1e58d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -37
app.py CHANGED
@@ -4,60 +4,41 @@ import torch
4
  from diffusers import DiffusionPipeline
5
  import gradio as gr
6
 
7
- HF_TOKEN = os.getenv("HF_TOKEN")
8
-
9
- model_id = "black-forest-labs/FLUX.1-dev"
10
  pipe = DiffusionPipeline.from_pretrained(
11
  model_id,
12
  torch_dtype=torch.bfloat16,
13
- low_cpu_mem_usage=True,
14
- token=HF_TOKEN
15
  )
16
 
 
17
  pipe.load_lora_weights("strangerzonehf/Flux-Icon-Kit-LoRA")
18
  pipe.fuse_lora()
19
 
20
- # GPU processing block
21
- @spaces.GPU(duration=60)
22
- def _run_gpu_inference(full_prompt, steps, guidance):
23
  pipe.to("cuda")
 
 
 
 
24
  image = pipe(
25
  prompt=full_prompt,
26
- num_inference_steps=steps,
27
- guidance_scale=guidance
28
- ).images[0]
 
29
  pipe.to("cpu")
30
  return image
31
 
32
- # Main execution loop with safe fallback handling
33
- def generate_icon(prompt, num_inference_steps=28, guidance_scale=3.5):
34
- full_prompt = f"Icon Kit, {prompt}, minimalist UI UX design element, flat line icon, uniform stroke, solid background"
35
- steps = int(num_inference_steps)
36
- guidance = float(guidance_scale)
37
-
38
- try:
39
- # Attempt to run on dynamic ZeroGPU hardware allocation
40
- return _run_gpu_inference(full_prompt, steps, guidance)
41
- except Exception as gpu_error:
42
- print(f"ZeroGPU queue full, routing to CPU fallback node: {gpu_error}")
43
- # Run safely on the free CPU instance container if queue times out
44
- pipe.to("cpu")
45
- image = pipe(
46
- prompt=full_prompt,
47
- num_inference_steps=steps,
48
- guidance_scale=guidance
49
- ).images[0]
50
- return image
51
-
52
  demo = gr.Interface(
53
  fn=generate_icon,
54
- inputs=[
55
- gr.Textbox(label="Icon Subject (e.g., 'a settings gear wheel')", placeholder="Enter icon concept..."),
56
- gr.Slider(minimum=15, maximum=40, value=28, step=1, label="Inference Steps"),
57
- gr.Slider(minimum=1.0, maximum=10.0, value=3.5, step=0.5, label="Guidance Scale")
58
- ],
59
  outputs=gr.Image(type="pil", label="Generated UI Icon Component"),
60
- title="Flux UI/UX Icon Kit Generator"
61
  )
62
 
63
  if __name__ == "__main__":
 
4
  from diffusers import DiffusionPipeline
5
  import gradio as gr
6
 
7
+ # Schnell does NOT require a gated license token, making it faster to load
8
+ model_id = "black-forest-labs/FLUX.1-schnell"
 
9
  pipe = DiffusionPipeline.from_pretrained(
10
  model_id,
11
  torch_dtype=torch.bfloat16,
12
+ low_cpu_mem_usage=True
 
13
  )
14
 
15
+ # Load your UI Icon LoRA
16
  pipe.load_lora_weights("strangerzonehf/Flux-Icon-Kit-LoRA")
17
  pipe.fuse_lora()
18
 
19
+ # REDUCED FOOTPRINT: Duration cut from 60 seconds down to only 15 seconds!
20
+ @spaces.GPU(duration=15)
21
+ def generate_icon(prompt):
22
  pipe.to("cuda")
23
+
24
+ full_prompt = f"Icon Kit, {prompt}, minimalist UI UX design element, flat line icon, uniform stroke, solid background"
25
+
26
+ # Schnell completes clean layouts in only 4 steps!
27
  image = pipe(
28
  prompt=full_prompt,
29
+ num_inference_steps=4,
30
+ guidance_scale=0.0 # Schnell performs best with 0.0 guidance
31
+ ).images
32
+
33
  pipe.to("cpu")
34
  return image
35
 
36
+ # Streamlined interface matching the fast execution loop
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  demo = gr.Interface(
38
  fn=generate_icon,
39
+ inputs=[gr.Textbox(label="Icon Subject (e.g., 'a settings gear wheel')")],
 
 
 
 
40
  outputs=gr.Image(type="pil", label="Generated UI Icon Component"),
41
+ title="Flux UI/UX Icon Kit Generator (Fast Schnell Edition)"
42
  )
43
 
44
  if __name__ == "__main__":