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
import gradio as gr
|
| 7 |
+
import numpy as np
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def load_json(load_dir_path, json_file_name):
|
| 12 |
+
|
| 13 |
+
load_path = os.path.join(load_dir_path, json_file_name)
|
| 14 |
+
if not os.path.exists(load_path):
|
| 15 |
+
return None
|
| 16 |
+
with open(load_path, 'r', encoding='utf-8') as f:
|
| 17 |
+
obj_serializable = json.load(f)
|
| 18 |
+
return obj_serializable
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def load_results_recaption(save_path, model="gpt-3.5-turbo-0125"):
|
| 22 |
+
result_list = load_json(save_path, f'final_results-{model}.json')
|
| 23 |
+
if result_list is not None:
|
| 24 |
+
result_list = result_list['result_list']
|
| 25 |
+
|
| 26 |
+
if result_list is None:
|
| 27 |
+
result_list = load_json(save_path, 'inference_results.json')
|
| 28 |
+
|
| 29 |
+
return result_list
|
| 30 |
+
|
| 31 |
+
plava_theme = gr.themes.Monochrome(
|
| 32 |
+
text_size="sm",
|
| 33 |
+
spacing_size="sm",
|
| 34 |
+
primary_hue=gr.themes.Color(c100="#f5f5f5", c200="#e5e5e5", c300="#d4d4d4", c400="#a3a3a3", c50="#fafafa", c500="#737373", c600="#525252", c700="#404040", c800="#262626", c900="#171717", c950="#000000"),
|
| 35 |
+
secondary_hue=gr.themes.Color(c100="#f5f5f5", c200="#e5e5e5", c300="#d4d4d4", c400="#a3a3a3", c50="#fafafa", c500="#737373", c600="#525252", c700="#404040", c800="#262626", c900="#171717", c950="#000000"),
|
| 36 |
+
neutral_hue=gr.themes.Color(c100="#f5f5f5", c200="#e5e5e5", c300="#d4d4d4", c400="#a3a3a3", c50="#fafafa", c500="#737373", c600="#525252", c700="#404040", c800="#262626", c900="#171717", c950="#000000"),
|
| 37 |
+
).set(
|
| 38 |
+
background_fill_primary_dark='*primary_950',
|
| 39 |
+
background_fill_secondary_dark='*neutral_950'
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
load_results_funcs = [
|
| 46 |
+
load_results_recaption,
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
recaption_root_dir = "recaption_results"
|
| 51 |
+
local_video_root_dir = "DATAS/Recaption/Inter4K/60fps/UHD"
|
| 52 |
+
remote_video_root_dir ="https://huggingface.co/datasets/ermu2001/Inter4kPlavaRecaption/resolve/main/DATAS/Recaption/Inter4K/60fps/UHD"
|
| 53 |
+
|
| 54 |
+
def show(result_list_first, result_list_second, result_index):
|
| 55 |
+
sample2index_second = {}
|
| 56 |
+
|
| 57 |
+
for i, result in enumerate(result_list_second):
|
| 58 |
+
if 'video_path' not in result:
|
| 59 |
+
continue
|
| 60 |
+
|
| 61 |
+
question = result['question'] if 'question' in result else ''
|
| 62 |
+
video_path = result['video_path']
|
| 63 |
+
samplehash = question + '--' +video_path
|
| 64 |
+
sample2index_second[samplehash] = i
|
| 65 |
+
|
| 66 |
+
info = result_list_first[result_index]
|
| 67 |
+
info_str_first = json.dumps(info, indent=4, ensure_ascii=False)
|
| 68 |
+
video_path = info['video_path']
|
| 69 |
+
question = info['question'] if 'question' in info else ''
|
| 70 |
+
samplehash = question + '--' +video_path
|
| 71 |
+
if samplehash in sample2index_second:
|
| 72 |
+
info = result_list_second[sample2index_second[samplehash]]
|
| 73 |
+
info_str_second = json.dumps(info, indent=4, ensure_ascii=False)
|
| 74 |
+
else:
|
| 75 |
+
info_str_second = f"NO {video_path} IN THE SECOND RESULT DIR"
|
| 76 |
+
video_path = video_path.replace(local_video_root_dir, remote_video_root_dir)
|
| 77 |
+
video_path = "https://huggingface.co/datasets/nielsr/video-demo/resolve/main/eating_spaghetti.mp4"
|
| 78 |
+
return video_path, info_str_first, info_str_second
|
| 79 |
+
|
| 80 |
+
def reload_results_dirs():
|
| 81 |
+
result_dirs = []
|
| 82 |
+
# load result dir paths
|
| 83 |
+
for dirpath, dirnames, filenames in os.walk(recaption_root_dir):
|
| 84 |
+
if len(dirnames) == 0 and len(filenames) != 0:
|
| 85 |
+
result_dirs.append(dirpath)
|
| 86 |
+
return gr.Dropdown(result_dirs, value=result_dirs[0])
|
| 87 |
+
|
| 88 |
+
def reload_results(result_dir):
|
| 89 |
+
# if isinstance(result_dir, list):
|
| 90 |
+
# result_dir = result_dir[0]
|
| 91 |
+
|
| 92 |
+
if result_dir is None or not osp.exists(result_dir):
|
| 93 |
+
return None
|
| 94 |
+
|
| 95 |
+
for fn in load_results_funcs:
|
| 96 |
+
result_list = fn(result_dir)
|
| 97 |
+
if result_list is not None:
|
| 98 |
+
np.random.shuffle(result_list)
|
| 99 |
+
break
|
| 100 |
+
result_index = gr.Slider(0, len(result_list), step=1)
|
| 101 |
+
|
| 102 |
+
return result_list, result_index
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
with gr.Blocks(title="PLAVA RESULTS", theme=plava_theme) as demo:
|
| 107 |
+
result_list_first = gr.State()
|
| 108 |
+
result_list_second = gr.State()
|
| 109 |
+
|
| 110 |
+
with gr.Row():
|
| 111 |
+
with gr.Column():
|
| 112 |
+
gr.Markdown("# Showing off Model's Outputs.")
|
| 113 |
+
gr.Markdown(
|
| 114 |
+
"You can find all our results, including:\n"
|
| 115 |
+
"1. results of Captioned Inter4k\n"
|
| 116 |
+
"2. results of Different Benchmark inference outputs.\n"
|
| 117 |
+
"Choose a directory to see the different output variant.\n"
|
| 118 |
+
"You can also choose secondary directory (as long as they are from the same dataset.) to compare on the results.\n"
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
with gr.Row():
|
| 122 |
+
with gr.Column():
|
| 123 |
+
show_video = gr.Video(interactive=False)
|
| 124 |
+
|
| 125 |
+
with gr.Column():
|
| 126 |
+
button_reload = gr.Button(value='Reload From The Evaluation/Inference Root Directory')
|
| 127 |
+
result_index = gr.Slider(0, 0, step=1, label="Index")
|
| 128 |
+
|
| 129 |
+
result_dir_first = gr.Dropdown(label='Test Result Path')
|
| 130 |
+
info_first = gr.Text(interactive=False, label='Detailed Output Information')
|
| 131 |
+
result_dir_second = gr.Dropdown(label='Test Result Path')
|
| 132 |
+
info_second = gr.Text(interactive=False, label='Detailed Output Information')
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
button_reload.click(reload_results_dirs, [], [result_dir_first])
|
| 136 |
+
button_reload.click(reload_results_dirs, [], [result_dir_second])
|
| 137 |
+
result_dir_first.change(reload_results, [result_dir_first], [result_list_first, result_index])
|
| 138 |
+
result_dir_second.change(reload_results, [result_dir_second], [result_list_second, result_index])
|
| 139 |
+
result_index.change(show, [result_list_first, result_list_second, result_index], [show_video, info_first, info_second])
|
| 140 |
+
demo.load(reload_results_dirs, [], [result_dir_first])
|
| 141 |
+
demo.load(reload_results_dirs, [], [result_dir_second])
|
| 142 |
+
|
| 143 |
+
demo.launch()
|
recaption_results/recaption_inter4k/inference_results.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
recaption_results/recaption_inter4k_ch/inference_results.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
numpy
|