Spaces:
Running
Running
lalashechka
commited on
Commit
·
410ba09
1
Parent(s):
849e813
Update app.py
Browse files
app.py
CHANGED
@@ -69,7 +69,29 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
|
|
69 |
continue
|
70 |
if status == 'failed':
|
71 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
css = """
|
74 |
#generate {
|
75 |
width: 100%;
|
@@ -89,6 +111,10 @@ display: flex;
|
|
89 |
justify-content: center;
|
90 |
}
|
91 |
footer {visibility: hidden !important;}
|
|
|
|
|
|
|
|
|
92 |
"""
|
93 |
|
94 |
with gr.Blocks(css=css) as demo:
|
@@ -113,12 +139,31 @@ with gr.Blocks(css=css) as demo:
|
|
113 |
cfg_scale = gr.Slider(show_label=True, label="CFG Scale:", minimum=1, maximum=20, value=7, step=1)
|
114 |
with gr.Row():
|
115 |
seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
with gr.Column():
|
117 |
text_button = gr.Button("Сгенерировать изображение", variant='primary', elem_id="generate")
|
118 |
-
with gr.Column(
|
119 |
-
image_output = gr.Image(show_label=True, label='Результат:', elem_id='image_output')
|
120 |
-
|
121 |
text_button.click(flip_text, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
demo.queue(concurrency_count=12)
|
124 |
demo.launch()
|
|
|
69 |
continue
|
70 |
if status == 'failed':
|
71 |
return None
|
72 |
+
|
73 |
+
|
74 |
+
def mirror(image_output, scale_by, method, gfpgan, codeformer):
|
75 |
+
|
76 |
+
url_up = os.getenv("url_up")
|
77 |
+
url_up_f = os.getenv("url_up_f")
|
78 |
+
|
79 |
+
scale_by = int(scale_by)
|
80 |
+
gfpgan = int(gfpgan)
|
81 |
+
codeformer = int(codeformer)
|
82 |
|
83 |
+
with open(image_output, "rb") as image_file:
|
84 |
+
encoded_string2 = base64.b64encode(image_file.read())
|
85 |
+
encoded_string2 = str(encoded_string2).replace("b'", '')
|
86 |
+
|
87 |
+
encoded_string2 = "data:image/png;base64," + encoded_string2
|
88 |
+
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":""}
|
89 |
+
print(data)
|
90 |
+
r = requests.post(f"{url_up}", json=data, timeout=100)
|
91 |
+
print(r.text)
|
92 |
+
ph = f"{url_up_f}" + str(r.json()['data'][0][0]['name'])
|
93 |
+
return ph
|
94 |
+
|
95 |
css = """
|
96 |
#generate {
|
97 |
width: 100%;
|
|
|
111 |
justify-content: center;
|
112 |
}
|
113 |
footer {visibility: hidden !important;}
|
114 |
+
|
115 |
+
#image_output {
|
116 |
+
height: 100% !important;
|
117 |
+
}
|
118 |
"""
|
119 |
|
120 |
with gr.Blocks(css=css) as demo:
|
|
|
139 |
cfg_scale = gr.Slider(show_label=True, label="CFG Scale:", minimum=1, maximum=20, value=7, step=1)
|
140 |
with gr.Row():
|
141 |
seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
|
142 |
+
|
143 |
+
with gr.Tab("Настройки апскейлинга"):
|
144 |
+
with gr.Column():
|
145 |
+
with gr.Row():
|
146 |
+
scale_by = gr.Number(show_label=True, label="Во сколько раз увеличить:", minimum=1, maximum=4, value=2, step=1)
|
147 |
+
with gr.Row():
|
148 |
+
method = gr.Dropdown(show_label=True, value="ESRGAN_4x", label="Алгоритм увеличения", choices=["ScuNET GAN", "SwinIR 4x", "ESRGAN_4x", "R-ESRGAN 4x+", "R-ESRGAN 4x+ Anime6B"])
|
149 |
+
with gr.Column():
|
150 |
+
with gr.Row():
|
151 |
+
gfpgan = gr.Slider(show_label=True, label="Эффект GFPGAN", minimum=0, maximum=1, value=0, step=0.1)
|
152 |
+
with gr.Row():
|
153 |
+
codeformer = gr.Slider(show_label=True, label="Эффект CodeFormer", minimum=0, maximum=1, value=0, step=0.1)
|
154 |
+
|
155 |
+
|
156 |
with gr.Column():
|
157 |
text_button = gr.Button("Сгенерировать изображение", variant='primary', elem_id="generate")
|
158 |
+
with gr.Column():
|
159 |
+
image_output = gr.Image(show_label=True, label='Результат:', elem_id='image_output', type='filepath')
|
|
|
160 |
text_button.click(flip_text, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output)
|
161 |
+
|
162 |
+
img2img_b = gr.Button("Увеличить изображение", variant='secondary')
|
163 |
+
image_i2i = gr.Image(show_label=True, label='Увеличенное изображение:')
|
164 |
+
img2img_b.click(mirror, inputs=[image_output, scale_by, method, gfpgan, codeformer], outputs=image_i2i)
|
165 |
+
|
166 |
+
|
167 |
|
168 |
demo.queue(concurrency_count=12)
|
169 |
demo.launch()
|