Spaces:
Running
Running
File size: 8,508 Bytes
7c1eee1 |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
import json
from functools import partial
from .utils import *
from .vote_utils import (
upvote_last_response_t2s as upvote_last_response,
downvote_last_response_t2s as downvote_last_response,
flag_last_response_t2s as flag_last_response,
leftvote_last_response_t2s_multi as leftvote_last_response,
rightvote_last_response_t2s_multi as rightvote_last_response,
tievote_last_response_t2s_multi as tievote_last_response,
bothbad_vote_last_response_t2s_multi as bothbad_vote_last_response,
share_click_t2s_multi as share_click,
share_js
)
from .inference import(
sample_prompt,
generate_t2s_multi
)
from .constants import TEXT_PROMPT_PATH
with open(TEXT_PROMPT_PATH, 'r') as f:
prompt_list = json.load(f)
def build_side_by_side_ui_named(models):
notice_markdown = """
# βοΈ GenAI-Arena βοΈ : Benchmarking Text-to-3D generative models
## π Rules
- Generate with any two selected models side-by-side and vote!
- Sample or Input prompt you want to generate.
- Click "Send" to submit the prompt.
- Click "Clear" to start a new round.
## π Arena Elo
Find out who is the π₯conditional image generation models! More models are going to be supported.
## π Generating now!
"""
model_list = models.get_t2s_models()
gen_func = partial(generate_t2s_multi, models.inference_parallel, models.render_parallel)
state_0 = gr.State()
state_1 = gr.State()
gr.Markdown(notice_markdown, elem_id="notice_markdown")
with gr.Group(elem_id="share-region-named"):
with gr.Row():
with gr.Column():
model_selector_left = gr.Dropdown(
choices=model_list,
value=model_list[0] if len(model_list) > 0 else "",
interactive=True,
show_label=False,
container=False,
)
with gr.Column():
model_selector_right = gr.Dropdown(
choices=model_list,
value=model_list[1] if len(model_list) > 1 else "",
interactive=True,
show_label=False,
container=False,
)
with gr.Accordion("π Expand to see all Arena players", open=False):
model_description_md = get_model_description_md(model_list)
gr.Markdown(model_description_md, elem_id="model_description_markdown")
with gr.Row():
with gr.Column():
normal_left = gr.Image(width=512, label = "Model A", show_copy_button=True)
rgb_left = gr.Image(width=512, label = "Model A", show_copy_button=True)
with gr.Column():
normal_right = gr.Image(width=512, label = "Model B", show_copy_button=True,)
rgb_right = gr.Image(width=512, label = "Model B", show_copy_button=True,)
with gr.Row():
slow_warning = gr.Markdown("", elem_id="notice_markdown")
with gr.Row(elem_id="Geometry Quality"):
geo_leftvote_btn = gr.Button(
value="π A is better", visible=False, interactive=False
)
geo_rightvote_btn = gr.Button(
value="π B is better", visible=False, interactive=False
)
geo_tie_btn = gr.Button(value="π€ Tie", visible=False, interactive=False)
geo_bothbad_btn = gr.Button(
value="π Both are bad", visible=False, interactive=False
)
with gr.Row(elem_id="Texture Quality"):
text_leftvote_btn = gr.Button(
value="π A is better", visible=False, interactive=False
)
text_rightvote_btn = gr.Button(
value="π B is better", visible=False, interactive=False
)
text_tie_btn = gr.Button(value="π€ Tie", visible=False, interactive=False)
text_bothbad_btn = gr.Button(
value="π Both are bad", visible=False, interactive=False
)
with gr.Row(elem_id="Alignment Quality"):
align_leftvote_btn = gr.Button(
value="π A is better", visible=False, interactive=False
)
align_rightvote_btn = gr.Button(
value="π B is better", visible=False, interactive=False
)
align_tie_btn = gr.Button(value="π€ Tie", visible=False, interactive=False)
align_bothbad_btn = gr.Button(
value="π Both are bad", visible=False, interactive=False
)
with gr.Row():
textbox = gr.Textbox(
show_label=False,
placeholder="π Enter your prompt or Sample a random prompt, and press ENTER",
container=True,
elem_id="input_box",
)
sample_btn = gr.Button(value="π² Sample", variant="primary", scale=0)
send_btn = gr.Button(value="π€ Send", variant="primary", scale=0)
with gr.Row():
clear_btn = gr.Button(value="ποΈ Clear", interactive=False)
regenerate_btn = gr.Button(value="π Regenerate", interactive=False)
share_btn = gr.Button(value="π· Share")
gr.Markdown(acknowledgment_md, elem_id="ack_markdown")
geo_btn_list = [geo_leftvote_btn, geo_rightvote_btn, geo_tie_btn, geo_bothbad_btn]
text_btn_list = [text_leftvote_btn, text_rightvote_btn, text_tie_btn, text_bothbad_btn]
align_btn_list = [align_leftvote_btn, align_rightvote_btn, align_tie_btn, align_bothbad_btn]
states = [state_0, state_1]
model_selectors = [model_selector_left, model_selector_right]
results = [normal_left, rgb_left, normal_right, rgb_right]
model_selector_left.change(
clear_history_side_by_side,
None,
states + [textbox] + results,
api_name="model_selector_left"
)
model_selector_right.change(
clear_history_side_by_side,
None,
states + [textbox] + results,
api_name="model_selector_right"
)
for btn_list in [geo_btn_list, text_btn_list, align_btn_list]:
leftvote_btn, rightvote_btn, tie_btn, bothbad_btn = btn_list
leftvote_btn.click(
leftvote_last_response,
states + model_selectors,
[textbox] + btn_list + model_selectors
)
rightvote_btn.click(
rightvote_last_response,
states + model_selectors,
[textbox] + btn_list + model_selectors
)
tie_btn.click(
tievote_last_response,
states + model_selectors,
[textbox] + btn_list + model_selectors
)
bothbad_btn.click(
bothbad_vote_last_response,
states + model_selectors,
[textbox] + btn_list + model_selectors
)
sample_btn.click(
sample_prompt,
states + model_selectors + [prompt_list],
states + [textbox],
api_name="sample_btn_named"
)
textbox.then(
gen_func,
states + [textbox] + model_selectors + [prompt_list],
states + results + model_selectors,
api_name="submit_btn_named"
).then(
enable_buttons_side_by_side,
None,
geo_btn_list + text_btn_list + align_btn_list + [regenerate_btn, clear_btn]
)
send_btn.click(
gen_func,
states + [textbox] + model_selectors + [prompt_list],
states + results + model_selectors,
api_name="send_btn_named"
).then(
enable_buttons_side_by_side,
None,
geo_btn_list + text_btn_list + align_btn_list + [regenerate_btn, clear_btn]
)
clear_btn.click(
clear_history_side_by_side_anony,
None,
states + [textbox] + results + model_selectors,
api_name="clear_btn_named"
).then(
disable_buttons_side_by_side,
None,
geo_btn_list + text_btn_list + align_btn_list + [regenerate_btn, clear_btn]
)
regenerate_btn.click(
gen_func,
states + [textbox] + model_selectors + [prompt_list],
states + results + model_selectors,
api_name="regenerate_btn_named"
).then(
enable_buttons_side_by_side,
None,
geo_btn_list + text_btn_list + align_btn_list + [regenerate_btn, clear_btn]
)
share_btn.click(
share_click,
states + model_selectors,
[],
js=share_js
)
|