Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,7 @@ app = FastAPI()
|
|
22 |
@app.get("/")
|
23 |
|
24 |
def query(prompt, negative_prompt, task, steps=35, sampler="DPM++ 2M Karras", cfg_scale=7, seed=-1, width=896, height=1152):
|
25 |
-
result = {prompt:"prompt", negative_prompt:"negative_prompt", task:"task", steps:"steps", sampler:"sampler", cfg_scale:
|
26 |
print(result)
|
27 |
try:
|
28 |
language = detect(prompt)
|
@@ -33,15 +33,13 @@ def query(prompt, negative_prompt, task, steps=35, sampler="DPM++ 2M Karras", cf
|
|
33 |
pass
|
34 |
|
35 |
prompt = re.sub(r'[^a-zA-Zа-яА-Я\s]', '', prompt)
|
36 |
-
|
37 |
|
38 |
cfg = int(cfg_scale)
|
39 |
steps = int(steps)
|
40 |
seed = int(seed)
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
progress=gr.Progress(track_tqdm=True)
|
45 |
|
46 |
if task == "Playground v2":
|
47 |
ua = UserAgent()
|
@@ -115,7 +113,7 @@ def query(prompt, negative_prompt, task, steps=35, sampler="DPM++ 2M Karras", cf
|
|
115 |
'user-agent': f'{ua.random}'
|
116 |
}
|
117 |
client = Client("Nymbo/SD-XL", headers=headers)
|
118 |
-
result = client.predict(prompt,negative_prompt,"","",True,False,False,0,
|
119 |
return result
|
120 |
except:
|
121 |
try:
|
@@ -171,7 +169,7 @@ def mirror(image_output, scale_by, method, gfpgan, codeformer):
|
|
171 |
encoded_string2 = str(encoded_string2).replace("b'", '')
|
172 |
|
173 |
encoded_string2 = "data:image/png;base64," + encoded_string2
|
174 |
-
data = {"fn_index":81,"data":[0,0,encoded_string2,None,"","",True,gfpgan,codeformer,0,scale_by,
|
175 |
r = requests.post(url_up, json=data, timeout=100)
|
176 |
print(r.text)
|
177 |
print(r.json()['data'][0][0]['name'])
|
@@ -197,49 +195,61 @@ footer {
|
|
197 |
"""
|
198 |
|
199 |
with gr.Blocks(css=css, theme=theme, fill_width= False) as app:
|
|
|
|
|
|
|
200 |
with gr.Tab("Basic Settings"):
|
201 |
-
with gr.
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
'
|
208 |
gr.Examples(
|
209 |
examples = examples,
|
210 |
inputs = [prompt],
|
211 |
)
|
212 |
-
|
|
|
213 |
with gr.Tab("Extended settings"):
|
214 |
-
with gr.
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
223 |
with gr.Row():
|
224 |
-
|
225 |
with gr.Row():
|
226 |
-
|
|
|
227 |
with gr.Row():
|
228 |
-
|
229 |
with gr.Row():
|
230 |
-
|
231 |
-
|
232 |
|
233 |
-
with gr.Column(
|
234 |
-
text_button = gr.Button("Generate image", variant=
|
235 |
-
with gr.Column(
|
236 |
-
image_output = gr.Image(show_download_button=True, interactive=False, label='
|
237 |
-
|
238 |
-
text_button.click(query, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed, width, height], outputs=image_output, concurrency_limit=48)
|
239 |
clear_prompt =gr.Button("Clear 🗑️",variant="primary", elem_id="clear_button")
|
240 |
clear_prompt.click(lambda: (None, None), None, [prompt, image_output], queue=False, show_api=False)
|
241 |
|
242 |
-
|
|
|
|
|
|
|
243 |
app.queue(default_concurrency_limit=200, max_size=200) # <-- Sets up a queue with default parameters
|
244 |
if __name__ == "__main__":
|
245 |
app.launch()
|
|
|
|
22 |
@app.get("/")
|
23 |
|
24 |
def query(prompt, negative_prompt, task, steps=35, sampler="DPM++ 2M Karras", cfg_scale=7, seed=-1, width=896, height=1152):
|
25 |
+
result = {prompt:"prompt", negative_prompt:"negative_prompt", task:"task", steps:"steps", sampler:"sampler", cfg_scale:print(result)
|
26 |
print(result)
|
27 |
try:
|
28 |
language = detect(prompt)
|
|
|
33 |
pass
|
34 |
|
35 |
prompt = re.sub(r'[^a-zA-Zа-яА-Я\s]', '', prompt)
|
|
|
36 |
|
37 |
cfg = int(cfg_scale)
|
38 |
steps = int(steps)
|
39 |
seed = int(seed)
|
40 |
+
|
41 |
+
width = 1024
|
42 |
+
height = 1024
|
|
|
43 |
|
44 |
if task == "Playground v2":
|
45 |
ua = UserAgent()
|
|
|
113 |
'user-agent': f'{ua.random}'
|
114 |
}
|
115 |
client = Client("Nymbo/SD-XL", headers=headers)
|
116 |
+
result = client.predict(prompt,negative_prompt,"","",True,False,False,0,1024,1024,7,1,25,25,False,api_name="/run")
|
117 |
return result
|
118 |
except:
|
119 |
try:
|
|
|
169 |
encoded_string2 = str(encoded_string2).replace("b'", '')
|
170 |
|
171 |
encoded_string2 = "data:image/png;base64," + encoded_string2
|
172 |
+
data = {"fn_index":81,"data":[0,0,encoded_string2,None,"","",True,gfpgan,codeformer,0,scale_by,512,512,None,method,"None",1,False,[],"",""],"session_hash":""}
|
173 |
r = requests.post(url_up, json=data, timeout=100)
|
174 |
print(r.text)
|
175 |
print(r.json()['data'][0][0]['name'])
|
|
|
195 |
"""
|
196 |
|
197 |
with gr.Blocks(css=css, theme=theme, fill_width= False) as app:
|
198 |
+
|
199 |
+
with gr.Blocks(css=css, theme=theme, fill_width= False) as app:
|
200 |
+
|
201 |
with gr.Tab("Basic Settings"):
|
202 |
+
with gr.Row():
|
203 |
+
prompt = gr.Textbox(placeholder="Enter the image description...", show_label=True, label='Description of the image:', lines=3)
|
204 |
+
with gr.Row():
|
205 |
+
task = gr.Radio(interactive=True, value="Stable Diffusion XL 1.0", show_label=True, label="Model of neural network:", choices=['Stable Diffusion XL 1.0', 'Crystal Clear XL',
|
206 |
+
'Juggernaut XL', 'DreamShaper XL',
|
207 |
+
'SDXL Niji', 'Cinemax SDXL', 'NightVision XL',
|
208 |
+
'Playground v2', 'Artigen v3'])
|
209 |
gr.Examples(
|
210 |
examples = examples,
|
211 |
inputs = [prompt],
|
212 |
)
|
213 |
+
|
214 |
+
|
215 |
with gr.Tab("Extended settings"):
|
216 |
+
with gr.Row():
|
217 |
+
negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=True, label='Negative Prompt:', lines=3, value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry")
|
218 |
+
with gr.Row():
|
219 |
+
sampler = gr.Dropdown(value="DPM++ SDE Karras", show_label=True, label="Sampling Method:", choices=[
|
220 |
+
"Euler", "Euler a", "Heun", "DPM++ 2M", "DPM++ SDE", "DPM++ 2M Karras", "DPM++ SDE Karras", "DDIM"])
|
221 |
+
with gr.Row():
|
222 |
+
steps = gr.Slider(show_label=True, label="Sampling Steps:", minimum=1, maximum=50, value=35, step=1)
|
223 |
+
with gr.Row():
|
224 |
+
cfg_scale = gr.Slider(show_label=True, label="CFG Scale:", minimum=1, maximum=20, value=7, step=1)
|
225 |
+
with gr.Row():
|
226 |
+
seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
|
227 |
+
|
228 |
+
with gr.Tab("Upscaling Settings"):
|
229 |
+
with gr.Column():
|
230 |
with gr.Row():
|
231 |
+
scale_by = gr.Number(show_label=True, label="How many times to increase:", minimum=1, maximum=2, value=2, step=1)
|
232 |
with gr.Row():
|
233 |
+
method = gr.Dropdown(show_label=True, value="ESRGAN_4x", label="Algorithm to enlarge", choices=["ScuNET GAN", "SwinIR 4x", "ESRGAN_4x", "R-ESRGAN 4x+", "R-ESRGAN 4x+ Anime6B"])
|
234 |
+
with gr.Column():
|
235 |
with gr.Row():
|
236 |
+
gfpgan = gr.Slider(show_label=True, label="Эффект GFPGAN (to improve the face)", minimum=0, maximum=1, value=0, step=0.1)
|
237 |
with gr.Row():
|
238 |
+
codeformer = gr.Slider(show_label=True, label="Effect CodeFormer (to improve the face)", minimum=0, maximum=1, value=0, step=0.1)
|
|
|
239 |
|
240 |
+
with gr.Column():
|
241 |
+
text_button = gr.Button("Generate image", variant='primary', elem_id="generate")
|
242 |
+
with gr.Column():
|
243 |
+
image_output = gr.Image(show_download_button=True, interactive=False, label='Результат:', elem_id='image_output', type='filepath')
|
244 |
+
text_button.click(flip_text, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output, concurrency_limit=48)
|
|
|
245 |
clear_prompt =gr.Button("Clear 🗑️",variant="primary", elem_id="clear_button")
|
246 |
clear_prompt.click(lambda: (None, None), None, [prompt, image_output], queue=False, show_api=False)
|
247 |
|
248 |
+
img2img_b = gr.Button("Increase the image", variant='secondary')
|
249 |
+
image_i2i = gr.Image(show_label=True, label='Increased image:')
|
250 |
+
img2img_b.click(mirror, inputs=[image_output, scale_by, method, gfpgan, codeformer], outputs=image_i2i, concurrency_limit=48)
|
251 |
+
|
252 |
app.queue(default_concurrency_limit=200, max_size=200) # <-- Sets up a queue with default parameters
|
253 |
if __name__ == "__main__":
|
254 |
app.launch()
|
255 |
+
|