lalashechka commited on
Commit
ee76b4a
1 Parent(s): ecd8121

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -3
app.py CHANGED
@@ -65,6 +65,8 @@ def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
65
  return photo
66
 
67
 
 
 
68
  def flipp():
69
  if task == 'Stable Diffusion XL 1.0':
70
  model = 'sd_xl_base_1.0'
@@ -97,6 +99,29 @@ def flipp():
97
  except:
98
  return None
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  css = """
101
  #generate {
102
  width: 100%;
@@ -112,6 +137,10 @@ css = """
112
  color: #fff;
113
  }
114
  footer {visibility: hidden !important;}
 
 
 
 
115
  """
116
 
117
  with gr.Blocks(css=css) as demo:
@@ -135,12 +164,28 @@ with gr.Blocks(css=css) as demo:
135
  cfg_scale = gr.Slider(show_label=True, label="CFG Scale:", minimum=1, maximum=20, value=7, step=1)
136
  with gr.Row():
137
  seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  with gr.Column():
139
  text_button = gr.Button("Сгенерировать изображение", variant='primary', elem_id="generate")
140
- with gr.Column(scale=2):
141
- image_output = gr.Image(show_label=True, label='Результат:', elem_id='image_output')
142
-
143
  text_button.click(flip_text, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output)
 
 
 
 
144
 
145
  demo.queue(concurrency_count=12)
146
  demo.launch()
 
65
  return photo
66
 
67
 
68
+
69
+
70
  def flipp():
71
  if task == 'Stable Diffusion XL 1.0':
72
  model = 'sd_xl_base_1.0'
 
99
  except:
100
  return None
101
 
102
+
103
+
104
+ def mirror(image_output, scale_by, method, gfpgan, codeformer):
105
+
106
+ url_up = os.getenv("url_up")
107
+ url_up_f = os.getenv("url_up_f")
108
+
109
+ scale_by = int(scale_by)
110
+ gfpgan = int(gfpgan)
111
+ codeformer = int(codeformer)
112
+
113
+ with open(image_output, "rb") as image_file:
114
+ encoded_string2 = base64.b64encode(image_file.read())
115
+ encoded_string2 = str(encoded_string2).replace("b'", '')
116
+
117
+ encoded_string2 = "data:image/png;base64," + encoded_string2
118
+ 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":""}
119
+ print(data)
120
+ r = requests.post(f"{url_up}", json=data, timeout=100)
121
+ print(r.text)
122
+ ph = f"{url_up_f}" + str(r.json()['data'][0][0]['name'])
123
+ return ph
124
+
125
  css = """
126
  #generate {
127
  width: 100%;
 
137
  color: #fff;
138
  }
139
  footer {visibility: hidden !important;}
140
+
141
+ #image_output {
142
+ height: 100% !important;
143
+ }
144
  """
145
 
146
  with gr.Blocks(css=css) as demo:
 
164
  cfg_scale = gr.Slider(show_label=True, label="CFG Scale:", minimum=1, maximum=20, value=7, step=1)
165
  with gr.Row():
166
  seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
167
+
168
+ with gr.Tab("Настройки апскейлинга"):
169
+ with gr.Column():
170
+ with gr.Row():
171
+ scale_by = gr.Number(show_label=True, label="Во сколько раз увеличить:", minimum=1, maximum=4, value=2, step=1)
172
+ with gr.Row():
173
+ method = gr.Dropdown(show_label=True, value="ESRGAN_4x", label="Алгоритм увеличения", choices=["ScuNET GAN", "SwinIR 4x", "ESRGAN_4x", "R-ESRGAN 4x+", "R-ESRGAN 4x+ Anime6B"])
174
+ with gr.Column():
175
+ with gr.Row():
176
+ gfpgan = gr.Slider(show_label=True, label="Эффект GFPGAN", minimum=0, maximum=1, value=0, step=0.1)
177
+ with gr.Row():
178
+ codeformer = gr.Slider(show_label=True, label="Эффект CodeFormer", minimum=0, maximum=1, value=0, step=0.1)
179
+
180
  with gr.Column():
181
  text_button = gr.Button("Сгенерировать изображение", variant='primary', elem_id="generate")
182
+ with gr.Column():
183
+ image_output = gr.Image(show_download_button=True, interactive=False, label='Результат:', elem_id='image_output', type='filepath')
 
184
  text_button.click(flip_text, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output)
185
+
186
+ img2img_b = gr.Button("Увеличить изображение", variant='secondary')
187
+ image_i2i = gr.Image(show_label=True, label='Увеличенное изображение:')
188
+ img2img_b.click(mirror, inputs=[image_output, scale_by, method, gfpgan, codeformer], outputs=image_i2i)
189
 
190
  demo.queue(concurrency_count=12)
191
  demo.launch()