kurilee commited on
Commit
ed7ec63
·
1 Parent(s): fd0dc20

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import LCMScheduler, AutoPipelineForText2Image
4
+
5
+ # model_id = "Lykon/dreamshaper-7"
6
+ # prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"
7
+
8
+ def run(checkpoint, prompt):
9
+ model_id = checkpoint
10
+ adapter_id = "latent-consistency/lcm-lora-sdv1-5"
11
+
12
+ pipe = AutoPipelineForText2Image.from_pretrained(model_id, torch_dtype=torch.float32, safety_checker=None).to("cpu")
13
+ pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
14
+
15
+ # load and fuse lcm lora
16
+ pipe.load_lora_weights(adapter_id)
17
+ pipe.fuse_lora()
18
+
19
+ # disable guidance_scale by passing 0
20
+ image = pipe(prompt=prompt, num_inference_steps=4, guidance_scale=0, width=512, height=512).images[0]
21
+ return image
22
+
23
+ with gr.Blocks() as demo:
24
+ input_checkpoint = gr.Text(value="Lykon/dreamshaper-7", label="Checkpoint")
25
+ input_prompt = gr.Text(value="Self-portrait oil painting, a beautiful cyborg with golden hair, 8k", label="Prompt")
26
+ out = gr.Image(type="pil")
27
+ btn = gr.Button("Run")
28
+ btn.click(fn=run, inputs=[input_checkpoint, input_prompt], outputs=out)
29
+
30
+ demo.launch()