Spaces:
Running
Running
root
commited on
Commit
·
d88d6cc
1
Parent(s):
9267c91
add sr choice
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import requests
|
|
| 7 |
import json
|
| 8 |
import ui_functions as uifn
|
| 9 |
from css_and_js import js, call_JS
|
|
|
|
| 10 |
|
| 11 |
txt2img_defaults = {
|
| 12 |
'prompt': '',
|
|
@@ -120,7 +121,26 @@ def request_images(raw_text, class_draw, style_draw, batch_size, sr_option):
|
|
| 120 |
# print(content[i])
|
| 121 |
images.append(base2picture(content[i]))
|
| 122 |
|
| 123 |
-
return images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
def encode_pil_to_base64(pil_image):
|
| 126 |
with io.BytesIO() as output_bytes:
|
|
@@ -247,11 +267,20 @@ if __name__ == "__main__":
|
|
| 247 |
).style(grid=[2], height="auto")
|
| 248 |
|
| 249 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
| 250 |
-
img_choices = gr.Dropdown(["图片1(img1)"],label='
|
| 251 |
output_txt2img_copy_to_input_btn = gr.Button("发送图片到图生图(Sent the image to img2img)").style(
|
| 252 |
margin=False,
|
| 253 |
rounded=(True, True, True, True),
|
| 254 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
# 并没有什么软用,转跳还是很卡,而且只能转跳一次
|
| 257 |
# go_to_img2img_btn = gr.Button("转至图生图(Go to img2img)").style(
|
|
@@ -263,6 +292,8 @@ if __name__ == "__main__":
|
|
| 263 |
gr.Examples(examples=examples, fn=request_images, inputs=text, outputs=gallery, examples_per_page=100)
|
| 264 |
text.submit(request_images, inputs=[text, class_draw, style_draw, sample_size, sr_option], outputs=gallery)
|
| 265 |
btn.click(request_images, inputs=[text, class_draw, style_draw, sample_size, sr_option], outputs=gallery)
|
|
|
|
|
|
|
| 266 |
|
| 267 |
sample_size.change(
|
| 268 |
fn=uifn.change_img_choices,
|
|
|
|
| 7 |
import json
|
| 8 |
import ui_functions as uifn
|
| 9 |
from css_and_js import js, call_JS
|
| 10 |
+
import re
|
| 11 |
|
| 12 |
txt2img_defaults = {
|
| 13 |
'prompt': '',
|
|
|
|
| 121 |
# print(content[i])
|
| 122 |
images.append(base2picture(content[i]))
|
| 123 |
|
| 124 |
+
return images
|
| 125 |
+
|
| 126 |
+
def sr_request_images(img_str, idx):
|
| 127 |
+
idx_map = {
|
| 128 |
+
"图片1(img1)":0,
|
| 129 |
+
"图片2(img2)":1,
|
| 130 |
+
"图片3(img3)":2,
|
| 131 |
+
"图片4(img4)":3,
|
| 132 |
+
}
|
| 133 |
+
idx = idx_map[idx]
|
| 134 |
+
image_data = re.sub('^data:image/.+;base64,', '', img_str[idx])
|
| 135 |
+
d = {"data":[image_data, 0]} # batch_size设置为0,
|
| 136 |
+
url = "http://flagart.baai.ac.cn/api/general/"
|
| 137 |
+
r = requests.post(url, json=d, headers={"Content-Type": "application/json", "Accept": "*/*", "Accept-Encoding": "gzip, deflate, br", "Connection": "keep-alive"})
|
| 138 |
+
result_text = r.text
|
| 139 |
+
content = json.loads(result_text)["data"][0]
|
| 140 |
+
images = [base2picture(content[0])]
|
| 141 |
+
|
| 142 |
+
return images
|
| 143 |
+
|
| 144 |
|
| 145 |
def encode_pil_to_base64(pil_image):
|
| 146 |
with io.BytesIO() as output_bytes:
|
|
|
|
| 267 |
).style(grid=[2], height="auto")
|
| 268 |
|
| 269 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
| 270 |
+
img_choices = gr.Dropdown(["图片1(img1)"],label='请选择一张图片发送到图生图或者超分',show_label=True,value="图片1(img1)")
|
| 271 |
output_txt2img_copy_to_input_btn = gr.Button("发送图片到图生图(Sent the image to img2img)").style(
|
| 272 |
margin=False,
|
| 273 |
rounded=(True, True, True, True),
|
| 274 |
)
|
| 275 |
+
output_txt2img_sr_btn = gr.Button("将选择的图片进行超分").style(
|
| 276 |
+
margin=False,
|
| 277 |
+
rounded=(True, True, True, True),
|
| 278 |
+
)
|
| 279 |
+
sr_gallery = gr.Gallery(
|
| 280 |
+
label="SR images", show_label=True, elem_id="sr_gallery"
|
| 281 |
+
).style(grid=[2], height="auto")
|
| 282 |
+
|
| 283 |
+
|
| 284 |
|
| 285 |
# 并没有什么软用,转跳还是很卡,而且只能转跳一次
|
| 286 |
# go_to_img2img_btn = gr.Button("转至图生图(Go to img2img)").style(
|
|
|
|
| 292 |
gr.Examples(examples=examples, fn=request_images, inputs=text, outputs=gallery, examples_per_page=100)
|
| 293 |
text.submit(request_images, inputs=[text, class_draw, style_draw, sample_size, sr_option], outputs=gallery)
|
| 294 |
btn.click(request_images, inputs=[text, class_draw, style_draw, sample_size, sr_option], outputs=gallery)
|
| 295 |
+
# to do here
|
| 296 |
+
output_txt2img_sr_btn.click(sr_request_images, inputs=[gallery, img_choices], outputs=[sr_gallery])
|
| 297 |
|
| 298 |
sample_size.change(
|
| 299 |
fn=uifn.change_img_choices,
|