Chan-Y commited on
Commit
e6416b2
1 Parent(s): ba9b8b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -1
app.py CHANGED
@@ -1,3 +1,147 @@
 
1
  import gradio as gr
 
 
 
2
 
3
- gr.load("models/Chan-Y/Stable-Flash-Lightning").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import DiffusionPipeline
2
  import gradio as gr
3
+ import numpy as np
4
+ import random
5
+ import torch
6
 
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+ dtype = torch.float16
9
+
10
+ pipe = DiffusionPipeline.from_pretrained("Chan-Y/Stable-Flash-Lightning",
11
+ torch_dtype=torch.float16).to(device)
12
+
13
+ MAX_SEED = 999999999999999
14
+ MAX_IMAGE_SIZE = 1344
15
+
16
+ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
17
+
18
+ if randomize_seed:
19
+ seed = random.randint(0, MAX_SEED)
20
+
21
+ generator = torch.Generator().manual_seed(seed)
22
+
23
+ image = pipe(
24
+ prompt = prompt,
25
+ negative_prompt = negative_prompt,
26
+ guidance_scale = guidance_scale,
27
+ num_inference_steps = num_inference_steps,
28
+ width = width,
29
+ height = height,
30
+ generator = generator
31
+ ).images[0]
32
+
33
+ return image, seed
34
+
35
+
36
+ examples = [
37
+ ["high quality, 8K Ultra HD, high detailed, masterpiece, A digital illustration of anime style, soft anime tones, Detailed illustration of many colorful soap bubbles falling from the sky on a beautiful woman, colorful colors, colorful woman, pink hair, blue eye, luminism, three dimensional effect, enhanced beauty, Albert Anker, Kyoto Animation, Greg Rutkowski, Artgerm, WLOP, Alphonse Beeple, luminism, 3d render, octane render, Isometric, by yukisakura, awesome full color,",
38
+ "nude, nsfw, text, letters, too many feet, too many fingers, long neck, 2 heads, duplicate, abstract, disfigured, deformed, toy, figure, framed, disfigured, bad art,deformed, poorly drawn, extra limbs, weird colors, 2 heads, elongated body, cropped image, out of frame, draft, deformed hands, twisted fingers, double image, malformed hands, multiple heads, extra limb, ugly, poorly drawn hands, missing limb, cut-off, over satured, grain, lowères, bad anatomy, poorly drawn face, mutation, mutated, floating limbs, disconnected limbs, out of focus, long body, disgusting, extra fingers, groos proportions, missing arms, mutated hands, cloned face, missing legs,",
39
+ 728456274845100,
40
+ 28],
41
+ ["cute catgirl , orange and white, with furry ears and striped tail, devious expression, full-body shot, 8K.",
42
+ "Double limbs, cross eyes, long limbs, deformed fingers, fat, ugly, missing body parts, pixelation",
43
+ 712099815579800,
44
+ 50],
45
+ ["pink female witch portrait beauty pretty soft dewy glow skin sparkle highlighter pink haired youthful witch web witch feminine retro vintage antique spiderwebs on her pointed pink witchhat wearing a spiderweb pink corset ribbon laced up, with dewdrops on a pink roses with spiderwebs with dewdrops on the webs halloween spiderwebs spider-web hd highres 4k 8k coquette aesthetic ",
46
+ "",
47
+ 711753355540400,
48
+ 50]
49
+ ]
50
+
51
+
52
+ css="""
53
+ #col-container {
54
+ margin: 0 auto;
55
+ max-width: 580px;
56
+ }
57
+ """
58
+
59
+
60
+ with gr.Blocks(css=css) as demo:
61
+
62
+ with gr.Column(elem_id="col-container"):
63
+ gr.Markdown(f"""
64
+ # Demo [Chan-Y/Stable-Flash-Lightning](https://huggingface.co/Chan-Y/Stable-Flash-Lightning)
65
+ My [LinkedIn](https://www.linkedin.com/in/chanyalcin/)
66
+ """)
67
+
68
+ with gr.Row():
69
+
70
+ prompt = gr.Text(
71
+ label="Prompt",
72
+ show_label=False,
73
+ max_lines=1,
74
+ placeholder="Enter your prompt",
75
+ container=False,
76
+ )
77
+
78
+ run_button = gr.Button("Run", scale=0)
79
+
80
+ result = gr.Image(label="Result", show_label=False)
81
+
82
+ with gr.Accordion("Advanced Settings", open=False):
83
+
84
+ negative_prompt = gr.Text(
85
+ label="Negative prompt",
86
+ max_lines=1,
87
+ placeholder="Enter a negative prompt",
88
+ )
89
+
90
+ seed = gr.Slider(
91
+ label="Seed",
92
+ minimum=0,
93
+ maximum=MAX_SEED,
94
+ step=1,
95
+ value=0,
96
+ )
97
+
98
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
99
+
100
+ with gr.Row():
101
+
102
+ width = gr.Slider(
103
+ label="Width",
104
+ minimum=256,
105
+ maximum=MAX_IMAGE_SIZE,
106
+ step=64,
107
+ value=1024,
108
+ )
109
+
110
+ height = gr.Slider(
111
+ label="Height",
112
+ minimum=256,
113
+ maximum=MAX_IMAGE_SIZE,
114
+ step=64,
115
+ value=1024,
116
+ )
117
+
118
+ with gr.Row():
119
+
120
+ guidance_scale = gr.Slider(
121
+ label="Guidance scale",
122
+ minimum=0.0,
123
+ maximum=10.0,
124
+ step=0.1,
125
+ value=5.0,
126
+ )
127
+
128
+ num_inference_steps = gr.Slider(
129
+ label="Number of inference steps",
130
+ minimum=1,
131
+ maximum=50,
132
+ step=1,
133
+ value=28,
134
+ )
135
+
136
+ gr.Examples(
137
+ examples = examples,
138
+ inputs = [prompt, negative_prompt, seed, num_inference_steps]
139
+ )
140
+ gr.on(
141
+ triggers=[run_button.click, prompt.submit, negative_prompt.submit],
142
+ fn = infer,
143
+ inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
144
+ outputs = [result, seed]
145
+ )
146
+
147
+ demo.launch()