Spaces:
Runtime error
Runtime error
Yuhao Song
commited on
Commit
·
58c076e
1
Parent(s):
d2d5e59
try
Browse files
app.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
root = "/mnt/ve_share/generation/data/result/diffusions/vis/instructpix2pix/official"
|
6 |
+
log_path = "/mnt/ve_share/generation/recordx.txt"
|
7 |
+
|
8 |
+
def feedback(feedback_text, model, scene):
|
9 |
+
output = "%s@%s@%s@%s" % (model, scene, feedback_text, length)
|
10 |
+
with open(log_path, "a") as input_file:
|
11 |
+
input_file.writelines(output + "\n")
|
12 |
+
print(output)
|
13 |
+
|
14 |
+
def get_file_paths(folder_path):
|
15 |
+
file_paths = []
|
16 |
+
for root, dirs, files in os.walk(folder_path):
|
17 |
+
for file in files:
|
18 |
+
file_path = os.path.join(root, file)
|
19 |
+
file_paths.append(file_path)
|
20 |
+
return file_paths
|
21 |
+
|
22 |
+
def generation_eval():
|
23 |
+
# print("request.headers: ", request.headers)
|
24 |
+
models = [f for f in os.listdir(root) if os.path.isdir(os.path.join(root, f))]
|
25 |
+
model_root = "%s/%s" % (root, models[-2])
|
26 |
+
scenes = [f for f in os.listdir(model_root) if os.path.isdir(os.path.join(model_root, f))]
|
27 |
+
|
28 |
+
def clip_api(model, scene):
|
29 |
+
# global feedback_btn
|
30 |
+
# feedback_btn = gr.Radio.update(choices=['未知(反馈可持续优化LSU🤗)', '准确率低(<30%)', '准确率中(30% ~ 80%)', '准确率高(>80%)',], value='未知(反馈可持续优化LSU🤗)')
|
31 |
+
ret_imgs = get_file_paths("%s/%s/%s" % (root, model, scene))
|
32 |
+
# print(ret_imgs)
|
33 |
+
global length
|
34 |
+
length = len(ret_imgs)
|
35 |
+
ret_imgs = [Image.open(_) for _ in ret_imgs]
|
36 |
+
return ret_imgs
|
37 |
+
|
38 |
+
examples = []
|
39 |
+
# examples = [
|
40 |
+
# ["道路上工作的环卫工人", 20, VLP, "是"],
|
41 |
+
# ["雨天打伞的人", 20, VLP, "是"],
|
42 |
+
# ["救护车", 20, VLP, "是"],
|
43 |
+
# ["校车", 20, VLP, "是"],
|
44 |
+
# ["警车", 20, VLP, "是"],
|
45 |
+
# ["喝水的人", 20, VLP, "是"],
|
46 |
+
# ["后备箱打开", 20, VLP, "是"],
|
47 |
+
# ]
|
48 |
+
|
49 |
+
title = "<h1 align='center'>图像生成人工评测平台</h1>"
|
50 |
+
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
gr.Markdown(title)
|
53 |
+
# gr.Markdown(description)
|
54 |
+
with gr.Row():
|
55 |
+
with gr.Column(scale=1):
|
56 |
+
# with gr.Column(scale=2):
|
57 |
+
# text = gr.Textbox(value="道路上工作的环卫工人", label="请填写文本", elem_id=0, interactive=True)
|
58 |
+
|
59 |
+
# num = gr.components.Slider(minimum=0, maximum=200, step=1, value=30, label="返回图片数", elem_id=2)
|
60 |
+
model = gr.components.Radio(label="模型选择", choices=models, value=models[0], elem_id=3)
|
61 |
+
scene = gr.components.Radio(label="场景选择", choices=scenes, value=scenes[0], elem_id=4)
|
62 |
+
# thumbnail = gr.components.Radio(label="是否返回缩略图", choices=["yes", "no"], value="yes", elem_id=4)
|
63 |
+
btn = gr.Button("搜索")
|
64 |
+
# feedback_btn = gr.Radio(label="检索结果反馈",
|
65 |
+
# choices=['未知(反馈可持续优化LSU🤗)', '准确率低(<30%)', '准确率中(30% ~ 80%)', '准确率高(>80%)',], value='未知(反馈可持续优化LSU🤗)')
|
66 |
+
with gr.Column(scale=100):
|
67 |
+
out = gr.Gallery(label="检索结果为:").style(grid=6, height=200)
|
68 |
+
feedback_btn = gr.Textbox(value="", label="请填写合格图像数", elem_id=0, interactive=True)
|
69 |
+
btn2 = gr.Button("提交")
|
70 |
+
|
71 |
+
# inputs = [text, num, model, thumbnail]
|
72 |
+
inputs = [model, scene]
|
73 |
+
btn.click(fn=clip_api, inputs=inputs, outputs=[out])
|
74 |
+
btn2.click(feedback, inputs=[feedback_btn, model, scene])
|
75 |
+
# feedback_btn.change(feedback, inputs=feedback_btn)
|
76 |
+
gr.Examples(examples, inputs=inputs)
|
77 |
+
return demo
|
78 |
+
|
79 |
+
|
80 |
+
if __name__ == "__main__":
|
81 |
+
with gr.TabbedInterface(
|
82 |
+
[generation_eval()],
|
83 |
+
["图像生成人工评测"],
|
84 |
+
) as demo:
|
85 |
+
demo.launch(
|
86 |
+
enable_queue=True,
|
87 |
+
share=True,
|
88 |
+
)
|