forked from ziqihuangg/Collaborative-Diffusion
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
53 lines (45 loc) · 1.93 KB
/
server.py
File metadata and controls
53 lines (45 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import gradio as gr
from generate_512 import predict, parse_args
from functools import partial
def gen_image(image_path, text):
args = parse_args()
args.mask_path = image_path[0]
args.input_text = text
print(args.mask_path)
save_mixed_path = predict(args)
return save_mixed_path
if __name__ == "__main__":
title = """<h1 align="center">Collaborative Diffusion (CVPR 2023)</h1>"""
theme = gr.themes.Soft()
with gr.Blocks(
css="""#col_container { margin-left: auto; margin-right: auto;}""",
theme=theme) as demo:
gr.HTML(title)
with gr.Row(elem_id="col_container"):
with gr.Column():
# gr.Markdown('Mask')
# in_image = gr.Image(
# type="filepath", label="请输入图片", source="upload")
# gr.Examples([
# 'test_data/512_masks/27007.png',
# 'test_data/512_masks/29980.png'
# ],
# inputs=in_image)
examples = gr.Dataset(
label="请选择 Mask",
components=[gr.Image(visible=False)],
samples=[['test_data/512_masks/27007.png'],
['test_data/512_masks/29980.png']])
# gr.Markdown('Prompt')
text = gr.Text(label='请输入文本', lines=5)
gr.Examples([
'This man has beard of medium length. He is in his thirties.',
'This woman is in her forties.'
],
inputs=text)
button = gr.Button('Generate', variant='primary')
with gr.Column():
out_image = gr.Image(type='filepath')
button.click(partial(gen_image), [examples, text], out_image)
gr.close_all()
demo.launch(share=True, debug=True)