File size: 4,442 Bytes
f239efc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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


import argparse
import json
import os
import os.path as osp
import gradio as gr
import numpy as np

from tasks.eval.recaption import load_results as load_results_recaption
from tasks.eval.mvbench import load_results as load_results_mvbench
from tasks.eval.vcgbench import load_results as load_results_vcgbench
from tasks.eval.videoqabench import load_results as load_results_videoqabench
from tasks.eval.demo import pllava_theme


load_results_funcs = [
    load_results_recaption,
    load_results_mvbench,
    load_results_vcgbench,
    load_results_videoqabench,
]


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--root_dir',
        required=True,
    )
    args = parser.parse_args()
    return args

args = parse_args()
root_dir = args.root_dir

def show(result_list_first, result_list_second, result_index):
    sample2index_second = {}

    for i, result in enumerate(result_list_second):
        if 'video_path' not in result:
            continue

        question = result['question'] if 'question' in result else ''
        video_path = result['video_path']
        samplehash = question + '--' +video_path
        sample2index_second[samplehash] = i

    info = result_list_first[result_index]
    info_str_first = json.dumps(info, indent=4, ensure_ascii=False)
    video_path = info['video_path']
    question = info['question'] if 'question' in info else ''
    samplehash = question + '--' +video_path
    if samplehash in sample2index_second:
        info = result_list_second[sample2index_second[samplehash]]
        info_str_second = json.dumps(info, indent=4, ensure_ascii=False)
    else:
        info_str_second = f"NO {video_path} IN THE SECOND RESULT DIR"
    return video_path, info_str_first, info_str_second

def reload_results_dirs():
    result_dirs = []
    # load result dir paths
    for dirpath, dirnames, filenames in os.walk(args.root_dir):
        if len(dirnames) == 0 and len(filenames) != 0:
            result_dirs.append(dirpath)
    return gr.Dropdown(result_dirs, value=result_dirs[0])

def reload_results(result_dir):
    # if isinstance(result_dir, list):
    #     result_dir = result_dir[0]

    if result_dir is None or not osp.exists(result_dir):
        return None
    
    for fn in load_results_funcs:
        result_list = fn(result_dir)
        if result_list is not None:
            np.random.shuffle(result_list)
            break
    result_index = gr.Slider(0, len(result_list), step=1)

    return result_list, result_index



with gr.Blocks(title="PLLAVA RESULTS", theme=pllava_theme) as demo:
    result_list_first = gr.State()
    result_list_second = gr.State()

    with gr.Row():
        with gr.Column():
            gr.Markdown("# Showing off Model's Outputs.")
            gr.Markdown(
                "You can find all our results, including:\n"
                "1. results of Captioned Inter4k\n"
                "2. results of Different Benchmark inference outputs.\n"
                "Choose a directory to see the different output variant.\n"
                "You can also choose secondary directory (as long as they are from the same dataset.) to compare on the results.\n"
            )

    with gr.Row():
        with gr.Column():
            show_video = gr.Video(interactive=False)

        with gr.Column():
            button_reload = gr.Button(value='Reload From The Evaluation/Inference Root Directory')
            result_index = gr.Slider(0, 0, step=1, label="Index")

            result_dir_first = gr.Dropdown(label='Test Result Path')
            info_first = gr.Text(interactive=False, label='Detailed Output Information')
            result_dir_second = gr.Dropdown(label='Test Result Path')
            info_second = gr.Text(interactive=False, label='Detailed Output Information')
        

    button_reload.click(reload_results_dirs, [], [result_dir_first])
    button_reload.click(reload_results_dirs, [], [result_dir_second])
    result_dir_first.change(reload_results, [result_dir_first], [result_list_first, result_index])
    result_dir_second.change(reload_results, [result_dir_second], [result_list_second, result_index])
    result_index.change(show, [result_list_first, result_list_second, result_index], [show_video, info_first, info_second])
    demo.load(reload_results_dirs, [], [result_dir_first])
    demo.load(reload_results_dirs, [], [result_dir_second])
    
demo.launch(share=True)