Spaces:
Runtime error
Runtime error
pengdaqian
commited on
Commit
•
e8c43c7
1
Parent(s):
44f1fd6
fix more
Browse files- app.py +35 -22
- model.py +1 -1
- requirements.txt +1 -1
app.py
CHANGED
@@ -44,6 +44,14 @@ rand = random.Random()
|
|
44 |
translator = google_translator()
|
45 |
|
46 |
pipe = get_sd_tiny()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
|
49 |
def infer(prompt: str, negative: str, width: int, height: int, sampler: str, steps: int, seed: int, scale):
|
@@ -54,37 +62,39 @@ def infer(prompt: str, negative: str, width: int, height: int, sampler: str, ste
|
|
54 |
else:
|
55 |
seed = int(seed)
|
56 |
|
|
|
|
|
57 |
images = []
|
58 |
if torch.cuda.is_available():
|
59 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
60 |
else:
|
61 |
generator = None
|
62 |
if sampler == "EulerDiscrete":
|
63 |
-
|
64 |
elif sampler == "EulerAncestralDiscrete":
|
65 |
-
|
66 |
elif sampler == "KDPM2Discrete":
|
67 |
-
|
68 |
elif sampler == "KDPM2AncestralDiscrete":
|
69 |
-
|
70 |
elif sampler == "UniPCMultistep":
|
71 |
-
|
72 |
elif sampler == "DPMSolverSinglestep":
|
73 |
-
|
74 |
elif sampler == "DPMSolverMultistep":
|
75 |
-
|
76 |
elif sampler == "HeunDiscrete":
|
77 |
-
|
78 |
elif sampler == "DEISMultistep":
|
79 |
-
|
80 |
elif sampler == "PNDM":
|
81 |
-
|
82 |
elif sampler == "DDPM":
|
83 |
-
|
84 |
elif sampler == "DDIM":
|
85 |
-
|
86 |
elif sampler == "LMSDiscrete":
|
87 |
-
|
88 |
|
89 |
try:
|
90 |
translate_prompt = translator.translate(prompt, lang_tgt='en')
|
@@ -94,13 +104,13 @@ def infer(prompt: str, negative: str, width: int, height: int, sampler: str, ste
|
|
94 |
translate_prompt = prompt
|
95 |
translate_negative = negative
|
96 |
|
97 |
-
image =
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
|
105 |
buffered = BytesIO()
|
106 |
image.save(buffered, format="JPEG")
|
@@ -133,7 +143,7 @@ css = """
|
|
133 |
padding-top: 1.5rem;
|
134 |
}
|
135 |
#prompt-column {
|
136 |
-
min-height:
|
137 |
}
|
138 |
#gallery {
|
139 |
min-height: 22rem;
|
@@ -360,7 +370,10 @@ with block:
|
|
360 |
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
361 |
Stable Diffusion 2.1 Demo App. <br />
|
362 |
Click "Generate image" Button to generate image. <br />
|
363 |
-
Also Change params to have a try
|
|
|
|
|
|
|
364 |
</p>
|
365 |
</div>
|
366 |
"""
|
|
|
44 |
translator = google_translator()
|
45 |
|
46 |
pipe = get_sd_tiny()
|
47 |
+
other_pipe = get_sd_small()
|
48 |
+
|
49 |
+
|
50 |
+
def get_pipe(width: int, height: int):
|
51 |
+
if width == 512 and height == 512:
|
52 |
+
return pipe
|
53 |
+
else:
|
54 |
+
return other_pipe
|
55 |
|
56 |
|
57 |
def infer(prompt: str, negative: str, width: int, height: int, sampler: str, steps: int, seed: int, scale):
|
|
|
62 |
else:
|
63 |
seed = int(seed)
|
64 |
|
65 |
+
pipeline = get_pipe(width, height)
|
66 |
+
|
67 |
images = []
|
68 |
if torch.cuda.is_available():
|
69 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
70 |
else:
|
71 |
generator = None
|
72 |
if sampler == "EulerDiscrete":
|
73 |
+
pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
|
74 |
elif sampler == "EulerAncestralDiscrete":
|
75 |
+
pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
|
76 |
elif sampler == "KDPM2Discrete":
|
77 |
+
pipeline.scheduler = KDPM2DiscreteScheduler.from_config(pipeline.scheduler.config)
|
78 |
elif sampler == "KDPM2AncestralDiscrete":
|
79 |
+
pipeline.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipeline.scheduler.config)
|
80 |
elif sampler == "UniPCMultistep":
|
81 |
+
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config)
|
82 |
elif sampler == "DPMSolverSinglestep":
|
83 |
+
pipeline.scheduler = DPMSolverSinglestepScheduler.from_config(pipeline.scheduler.config)
|
84 |
elif sampler == "DPMSolverMultistep":
|
85 |
+
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
|
86 |
elif sampler == "HeunDiscrete":
|
87 |
+
pipeline.scheduler = HeunDiscreteScheduler.from_config(pipeline.scheduler.config)
|
88 |
elif sampler == "DEISMultistep":
|
89 |
+
pipeline.scheduler = DEISMultistepScheduler.from_config(pipeline.scheduler.config)
|
90 |
elif sampler == "PNDM":
|
91 |
+
pipeline.scheduler = PNDMScheduler.from_config(pipeline.scheduler.config)
|
92 |
elif sampler == "DDPM":
|
93 |
+
pipeline.scheduler = DDPMScheduler.from_config(pipeline.scheduler.config)
|
94 |
elif sampler == "DDIM":
|
95 |
+
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
|
96 |
elif sampler == "LMSDiscrete":
|
97 |
+
pipeline.scheduler = LMSDiscreteScheduler.from_config(pipeline.scheduler.config)
|
98 |
|
99 |
try:
|
100 |
translate_prompt = translator.translate(prompt, lang_tgt='en')
|
|
|
104 |
translate_prompt = prompt
|
105 |
translate_negative = negative
|
106 |
|
107 |
+
image = pipeline(prompt=translate_prompt,
|
108 |
+
negative_prompt=translate_negative,
|
109 |
+
guidance_scale=scale,
|
110 |
+
num_inference_steps=steps,
|
111 |
+
generator=generator,
|
112 |
+
height=height,
|
113 |
+
width=width).images[0]
|
114 |
|
115 |
buffered = BytesIO()
|
116 |
image.save(buffered, format="JPEG")
|
|
|
143 |
padding-top: 1.5rem;
|
144 |
}
|
145 |
#prompt-column {
|
146 |
+
min-height: 520px
|
147 |
}
|
148 |
#gallery {
|
149 |
min-height: 22rem;
|
|
|
370 |
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
371 |
Stable Diffusion 2.1 Demo App. <br />
|
372 |
Click "Generate image" Button to generate image. <br />
|
373 |
+
Also Change params to have a try <br />
|
374 |
+
512*512 is optimized, every image will cost 30s. <br />
|
375 |
+
other size may cost more time. <br />
|
376 |
+
It's just a simplified demo, you can use more advanced features optimize image quality <br />
|
377 |
</p>
|
378 |
</div>
|
379 |
"""
|
model.py
CHANGED
@@ -46,4 +46,4 @@ def get_sd_tiny():
|
|
46 |
pipe = OVStableDiffusionPipeline.from_pretrained("OpenVINO/stable-diffusion-2-1-quantized", compile=False)
|
47 |
pipe.reshape(batch_size=1, height=512, width=512, num_images_per_prompt=1)
|
48 |
pipe.compile()
|
49 |
-
return pipe
|
|
|
46 |
pipe = OVStableDiffusionPipeline.from_pretrained("OpenVINO/stable-diffusion-2-1-quantized", compile=False)
|
47 |
pipe.reshape(batch_size=1, height=512, width=512, num_images_per_prompt=1)
|
48 |
pipe.compile()
|
49 |
+
return pipe
|
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
python-dotenv
|
2 |
diffusers
|
3 |
-
transformers
|
4 |
accelerate
|
5 |
scipy
|
6 |
safetensors
|
|
|
1 |
python-dotenv
|
2 |
diffusers
|
3 |
+
transformers<5
|
4 |
accelerate
|
5 |
scipy
|
6 |
safetensors
|