CryptoCreeper commited on
Commit
9bef04c
·
verified ·
1 Parent(s): d9ce0a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import DiffusionPipeline
4
+
5
+ device = "cpu"
6
+ if torch.cuda.is_available():
7
+ device = "cuda"
8
+
9
+ model_id = "SimianLuo/LCM_Dreamshaper_v7"
10
+
11
+ pipe = DiffusionPipeline.from_pretrained(model_id)
12
+ pipe.to(device)
13
+
14
+ def generate_image(prompt, width, height, steps):
15
+ result = pipe(
16
+ prompt=prompt,
17
+ width=int(width),
18
+ height=int(height),
19
+ num_inference_steps=int(steps),
20
+ guidance_scale=8.0,
21
+ lcm_origin_steps=50,
22
+ output_type="pil"
23
+ ).images[0]
24
+ return result
25
+
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("## LCM Image Generator (CPU Optimized)")
28
+
29
+ with gr.Row():
30
+ with gr.Column():
31
+ prompt_input = gr.Textbox(label="Prompt", placeholder="A futuristic city with neon lights...")
32
+
33
+ with gr.Row():
34
+ width_slider = gr.Slider(minimum=256, maximum=768, step=64, value=512, label="Width")
35
+ height_slider = gr.Slider(minimum=256, maximum=768, step=64, value=512, label="Height")
36
+
37
+ steps_slider = gr.Slider(minimum=1, maximum=15, step=1, value=4, label="Inference Steps (Quality)")
38
+
39
+ generate_btn = gr.Button("Generate Image")
40
+
41
+ with gr.Column():
42
+ image_output = gr.Image(label="Generated Image")
43
+
44
+ generate_btn.click(
45
+ fn=generate_image,
46
+ inputs=[prompt_input, width_slider, height_slider, steps_slider],
47
+ outputs=image_output
48
+ )
49
+
50
+ demo.launch()