Spaces:
Running
Running
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_model, | |
sample_prompt, | |
generate_t2s, | |
generate_t2s_multi, | |
generate_t2s_multi_annoy | |
) | |
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_anony(models): | |
notice_markdown = """ | |
# βοΈ GenAI-Arena βοΈ : Benchmarking Text-to-3D generative models | |
## π Rules | |
- Input prompt to two anonymous models in same area and vote for the better one! | |
- When the results are ready, click the button below to vote. | |
- Vote won't be counted if model identity is revealed during conversation. | |
- 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_annoy, models.inference_parallel_anony, 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-anony"): | |
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(): | |
with gr.Column(): | |
model_selector_left =gr.Markdown("", visible=False) | |
with gr.Column(): | |
model_selector_right = gr.Markdown("", visible=False) | |
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] | |
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_anony" | |
) | |
textbox.submit( | |
sample_model, | |
states + [model_list, False], | |
states + model_selectors | |
).then( | |
gen_func, | |
states + [textbox] + model_selectors + [prompt_list], | |
states + results + model_selectors, | |
api_name="submit_btn_anony" | |
).then( | |
enable_buttons_side_by_side, | |
None, | |
geo_btn_list + text_btn_list + align_btn_list + [regenerate_btn, clear_btn] | |
) | |
send_btn.click( | |
sample_model, | |
states + [model_list, False], | |
states + model_selectors | |
).then( | |
gen_func, | |
states + [textbox] + model_selectors + [prompt_list], | |
states + results + model_selectors, | |
api_name="send_btn_anony" | |
).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_anony" | |
).then( | |
disable_buttons_side_by_side, | |
None, | |
geo_btn_list + text_btn_list + align_btn_list + [regenerate_btn, clear_btn] | |
) | |
regenerate_btn.click( | |
sample_model, | |
states + [model_list, False], | |
states + model_selectors | |
).then( | |
gen_func, | |
states + [textbox] + model_selectors + [prompt_list], | |
states + results + model_selectors, | |
api_name="regenerate_btn_anony" | |
).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 | |
) | |