ciCic commited on
Commit
6a908d9
1 Parent(s): b3a9d1a
Files changed (2) hide show
  1. app.py +48 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ import torch
5
+ from diffusers import AutoPipelineForText2Image, LCMScheduler
6
+ from torchvision.transforms.functional import to_pil_image, center_crop, resize, to_tensor
7
+
8
+ device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
9
+
10
+ model_id = "Lykon/dreamshaper-7"
11
+ adapter_id = "latent-consistency/lcm-lora-sdv1-5"
12
+
13
+ pipe = AutoPipelineForText2Image.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16")
14
+ pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
15
+ pipe.to(device)
16
+
17
+ # load and fuse lcm lora
18
+ pipe.load_lora_weights(adapter_id)
19
+ pipe.fuse_lora()
20
+
21
+ prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"
22
+
23
+
24
+ @torch.no_grad()
25
+ def generate(prompt, guidance_scale):
26
+ image = pipe(prompt=prompt, num_inference_steps=4, guidance_scale=guidance_scale).images[0]
27
+ return image
28
+
29
+
30
+ def app():
31
+ return gr.Interface(generate,
32
+ [gr.Textbox(
33
+ label="Prompt",
34
+ info="Enter your prompt",
35
+ lines=3,
36
+ value="Self-portrait oil painting, a beautiful cyborg with golden hair, 8k",
37
+ ),
38
+ gr.Slider(2, 20, value=7.5, label="Guidance Scale",
39
+ info="Higher scale depicts more creativity")],
40
+ gr.Image(type="pil",
41
+ height=512,
42
+ width=512
43
+ )
44
+ , allow_flagging='never', title='Gen Image')
45
+
46
+
47
+ if __name__ == "__main__":
48
+ app().launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ transformers
4
+ diffusers
5
+ pillow
6
+ accelerate