File size: 13,264 Bytes
7cbbfe6
 
 
 
 
c24db25
7cbbfe6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55a84fb
96c5fd7
55a84fb
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5fd7
 
 
 
 
7cbbfe6
96c5fd7
 
55a84fb
7cbbfe6
96c5fd7
55a84fb
96c5fd7
55a84fb
96c5fd7
 
 
 
 
 
55a84fb
96c5fd7
 
 
 
 
55a84fb
 
 
96c5fd7
 
 
 
 
55a84fb
 
 
 
 
 
 
 
 
 
 
 
 
96c5fd7
55a84fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7cbbfe6
 
 
 
55a84fb
7cbbfe6
 
 
55a84fb
 
 
 
 
4c9bd23
 
 
 
 
 
 
 
 
 
 
 
 
 
55a84fb
7cbbfe6
55a84fb
 
 
 
 
 
 
4c9bd23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa4bb08
 
55a84fb
fa4bb08
e585775
4c9bd23
e585775
 
55a84fb
4c9bd23
e585775
55a84fb
4c9bd23
55a84fb
 
 
 
 
4c9bd23
 
 
55a84fb
 
 
 
 
 
4c9bd23
 
55a84fb
e585775
55a84fb
 
4c9bd23
55a84fb
 
e585775
55a84fb
 
4c9bd23
 
 
 
 
 
 
55a84fb
 
 
 
96c5fd7
55a84fb
 
96c5fd7
55a84fb
 
96c5fd7
55a84fb
 
 
 
 
 
 
 
 
 
 
96c5fd7
 
55a84fb
 
 
 
 
 
 
 
 
 
 
 
8199846
55a84fb
4f3020b
 
 
 
 
 
96c5fd7
8199846
55a84fb
 
 
8199846
55a84fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96c5fd7
e24a92e
 
4f3020b
 
 
 
 
 
 
 
 
8199846
4f3020b
 
 
 
 
 
 
 
 
e24a92e
4f3020b
4c9bd23
4f3020b
 
4c9bd23
 
 
 
 
 
7cbbfe6
 
 
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
__all__ = ['block', 'make_clickable_model', 'make_clickable_user', 'get_submissions']
import os
import io
import gradio as gr
import pandas as pd
import json
import shutil
import tempfile
import datetime
import zipfile
import numpy as np


from constants import *
from huggingface_hub import Repository
HF_TOKEN = os.environ.get("HF_TOKEN")

global data_component, filter_component


def upload_file(files):
    file_paths = [file.name for file in files]
    return file_paths


def add_new_eval(
    input_file,
    model_type,
    model_name_textbox,
    model_ability,
    revision_name_textbox,
    access_type,
    model_link,
    team_name,
    contact_email,
    release_time,
    model_resolution,
    model_length,
    model_fps,
    model_frame,
    model_link_optional,
):
    if input_file is None:
        return "Error! Empty file!"
    if  model_link == '' or model_name_textbox == '' or contact_email == '':
        return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)
    
    submission_repo = Repository(local_dir=SUBMISSION_NAME, clone_from=SUBMISSION_URL, use_auth_token=HF_TOKEN, repo_type="dataset")
    submission_repo.git_pull()
    filename = f"{model_name_textbox}_{model_type}_{model_ability}_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}"
    
    now = datetime.datetime.now()
    update_time = now.strftime("%Y.%m.%d")  # Capture update time

    csv_data = pd.read_csv(CSV_DIR)

    if revision_name_textbox == '':
        col = csv_data.shape[0]
        model_name = model_name_textbox.replace(',',' ')
    else:
        model_name = revision_name_textbox.replace(',',' ')
        model_name_list = csv_data['Model Name']
        name_list = [name.split(']')[0][1:] for name in model_name_list]
        if revision_name_textbox not in name_list:
            col = csv_data.shape[0]
        else:
            col = name_list.index(revision_name_textbox)    
            if csv_data[col]['Sampled by'] == "WorldScore" or csv_data[col]['Evaluated by'] == "WorldScore":
                return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)

    if model_link == '':
        model_name = model_name  # no url
    else:
        model_name = '[' + model_name + '](' + model_link + ')'

    if model_link_optional == '':
        model_link_optional = model_link
        
    try:
        with open(input_file, 'r') as f:
            upload_data = json.load(f)
    
        # add new data
        print('upload_data:', upload_data)
        new_data = [model_type, model_name, model_ability]
        if team_name == '':
            new_data.append(model_name)
            new_data.append(model_name)
        else:
            new_data.append(team_name)
            new_data.append(team_name)
        new_data.append(access_type)
        new_data.append(update_time)
        
        for key in TASK_INFO:
            value = COLNAME2KEY[key]
            if value in upload_data:
                new_data.append(upload_data[value])
            else:
                return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)
        
        
        csv_data.loc[col] = new_data
        csv_data = csv_data.to_csv(CSV_DIR, index=False)
        with open(INFO_DIR,'a') as f:
            f.write(f"{model_type.replace(',', ' ')}\t{model_name.replace(',', ' ')}\t{model_ability.replace(',', ' ')}\t{model_resolution.replace(',', ' ')}\t{model_length.replace(',', ' ')}\t{model_fps.replace(',', ' ')}\t{model_frame.replace(',', ' ')}\t{model_link_optional.replace(',', ' ')}\t{contact_email.replace(',', ' ')}\n")
        submission_repo.push_to_hub()
        print("success update", model_name)
        return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
    except:
        return gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)
    
    
def get_baseline_df():
    submission_repo = Repository(local_dir=SUBMISSION_NAME, clone_from=SUBMISSION_URL, use_auth_token=HF_TOKEN, repo_type="dataset")
    submission_repo.git_pull()
    df = pd.read_csv(CSV_DIR)
    df = df.sort_values(by=DEFAULT_INFO[0], ascending=False)  
    return df


block = gr.Blocks(css="""
    .container {
        max-width: 80%;
        margin: auto;
    }
    /* 添加以下样式来控制表格列宽 */
    .gradio-dataframe {
        overflow-x: auto !important;
    }
    .gradio-dataframe table {
        width: 100% !important;
        white-space: nowrap !important;
    }
    .gradio-dataframe td, .gradio-dataframe th {
        min-width: fit-content !important;
        max-width: none !important;
        white-space: pre-wrap !important;
        padding: 8px !important;
    }
""")
with block:
    with gr.Column(elem_classes="container"):
        gr.Markdown(
            LEADERBORAD_INTRODUCTION
        )
        with gr.Tabs(elem_classes="tab-buttons") as tabs:
            # Table 0
            with gr.TabItem("🏅 WorldScore Benchmark", elem_id="worldscore-tab-table", id=0):
                with gr.Row():
                    with gr.Column(scale=0.3):
                        model_type_filter = gr.CheckboxGroup(
                            choices=MODEL_TYPE,
                            value=DEFAULT_MODEL_TYPE,
                            label="Model Type",
                            interactive=True
                        )
                        ability_filter = gr.CheckboxGroup(
                            choices=ABILITY,
                            value=DEFAULT_ABILITY,
                            label="Ability",
                            interactive=True
                        )
                    with gr.Column(scale=0.7):
                        sort_by_filter = gr.Radio(
                            choices=TASK_INFO,
                            value=DEFAULT_INFO[0],
                            label="Sort by",
                            interactive=True
                        )
                
                df = get_baseline_df()
                data_component = gr.components.Dataframe(
                    value=df,
                    headers=COLUMN_NAMES,
                    type="pandas",
                    datatype=DATA_TITILE_TYPE,
                    interactive=False,
                    visible=True,
                    wrap=True
                )
        
                def on_filter_change(model_types, abilities, sort_by):
                    df = get_baseline_df()
                    # Filter by selected model types
                    df = df[df['Model Type'].isin(model_types)]
                    # Filter by selected abilities 
                    df = df[df['Ability'].isin(abilities)]
                    # Sort by selected sort by
                    df = df.sort_values(by=sort_by, ascending=False)
                    
                    return gr.Dataframe(
                        value=df,
                        headers=COLUMN_NAMES,
                        type="pandas",
                        datatype=DATA_TITILE_TYPE,
                        interactive=False,
                        visible=True,
                        wrap=True
                    )

                model_type_filter.change(
                    fn=on_filter_change,
                    inputs=[model_type_filter, ability_filter, sort_by_filter],
                    outputs=data_component
                )

                ability_filter.change(
                    fn=on_filter_change,
                    inputs=[model_type_filter, ability_filter, sort_by_filter], 
                    outputs=data_component
                )
                
                sort_by_filter.change(
                    fn=on_filter_change,
                    inputs=[model_type_filter, ability_filter, sort_by_filter],
                    outputs=data_component
                )
                    
            with gr.TabItem("🚀 Submit here! ", elem_id="submit-tab-table", id=1):

                with gr.Row():
                    gr.Markdown(SUBMIT_INTRODUCTION, elem_classes="markdown-text")

                with gr.Row():
                    gr.Markdown("# Submit your evaluation json file here!", elem_classes="markdown-text")

                with gr.Row():
                    gr.Markdown("Here is a required field", elem_classes="markdown-text")
                with gr.Row():
                    with gr.Column():
                        model_type = gr.Dropdown(["Video", "3D", "4D"], label="Model Type")
                        model_name_textbox = gr.Textbox(
                            label="Model name", placeholder="Your model name"
                            )
                        model_ability = gr.Dropdown(["I2V", "T2V"], label="Model Ability")
                        revision_name_textbox = gr.Textbox(
                            label="Revision Model Name (Optional)", placeholder="If you need to update the previous submissions, please fill in this line"
                        )

                    with gr.Column():
                        access_type = gr.Dropdown(["Open Source", "Ready to Open Source", "API", "Close"], label="Access")
                        model_link = gr.Textbox(
                            label="Link (Website/Paper Link/Github/HuggingFace)", placeholder="If filling in the wrong information, your results may be removed."
                        )
                        team_name = gr.Textbox(
                            label="Your Team Name", placeholder="If left blank, it will be your model name"
                        )
                        contact_email = gr.Textbox(
                            label="E-Mail (Will not be displayed)", placeholder="Contact email"
                        )
                with gr.Row():
                    gr.Markdown("The following is optional and will be synced to [GitHub](https://github.com/haoyi-duan/WorldScore/blob/main/README.md#world-generation-models-info)", elem_classes="markdown-text")
                with gr.Row():
                    release_time = gr.Textbox(label="Version", placeholder="2025.03.29")
                    model_resolution = gr.Textbox(label="Resolution", placeholder="WidthxHeight")
                    model_length = gr.Textbox(label="Video Length (s)", placeholder="float")
                    model_fps = gr.Textbox(label="FPS", placeholder="int")
                    model_frame = gr.Textbox(label="Frame Number", placeholder="int")
                    model_link_optional = gr.Textbox(label="Link", placeholder='optional')
                with gr.Column():
                    input_file = gr.components.File(label = "Click to Upload a JSON File", file_count="single", file_types=[".json"])
                    submit_button = gr.Button("Submit Eval")
                    submit_succ_button = gr.Markdown("Submit Success! Please press refresh and return to WorldScore Benchmark!", visible=False)
                    fail_textbox = gr.Markdown('<span style="color:red;">Please ensure that the `Model Name`, `Project Page`, and `E-mail` are filled in correctly and the uploaded json file is valid.</span>', elem_classes="markdown-text",visible=False)
                            
                    submission_result = gr.Markdown()
                    submit_button.click(
                        add_new_eval,
                        inputs = [
                            input_file,
                            model_type,
                            model_name_textbox,
                            model_ability,
                            revision_name_textbox,
                            access_type,
                            model_link,
                            team_name,
                            contact_email,
                            release_time,
                            model_resolution,
                            model_length,
                            model_fps,
                            model_frame,
                            model_link_optional,
                        ],
                        outputs=[submit_button, submit_succ_button, fail_textbox]
                    )


    def refresh_data():
        model_type_filter.value = DEFAULT_MODEL_TYPE
        ability_filter.value = DEFAULT_ABILITY
        sort_by_filter.value = DEFAULT_INFO[0]
        df = get_baseline_df()
        
        df = df[df['Model Type'].isin(model_type_filter.value)]
        df = df[df['Ability'].isin(ability_filter.value)]
        df = df.sort_values(by=sort_by_filter.value, ascending=False)
            
        data_component = gr.Dataframe(
            value=df,
            headers=COLUMN_NAMES,
            type="pandas",
            datatype=DATA_TITILE_TYPE,
            interactive=False,
            visible=True,
            wrap=True
        )

        return data_component, model_type_filter, ability_filter, sort_by_filter

    with gr.Row(elem_classes="container"):
        with gr.Column():
            data_run = gr.Button("Refresh")
            data_run.click(
                refresh_data, 
                inputs=[], 
                outputs=[data_component, model_type_filter, ability_filter, sort_by_filter]
            )


block.launch()