File size: 8,158 Bytes
7c1eee1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8f1d3f
7c1eee1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8f1d3f
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
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
    )