sergiopaniego HF Staff commited on
Commit
9b2cf74
·
1 Parent(s): eb3100d

Add application file

Browse files
Files changed (1) hide show
  1. app.py +132 -0
app.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import gradio.themes.base
3
+
4
+ from utils import *
5
+ from data_utils import *
6
+
7
+ from datasets import load_dataset
8
+
9
+ # Dummy
10
+ ds = load_dataset("visionLMsftw/vibe-testing-samples", split="train")
11
+ models = get_model_names()
12
+ evaluation_data = get_evaluation_data(ds)
13
+ responses = get_responses()
14
+
15
+
16
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
17
+ gr.Markdown("# VLMVibeEval")
18
+ gr.Markdown("VLM evaluation leaderboard based on vibes.")
19
+ mode = gr.Radio(["View model-wise responses", "Compare model responses on a specific example"], label="Mode", value="View model-wise responses")
20
+
21
+ with gr.Column(visible=True) as model_mode:
22
+ selected_model = gr.Dropdown(models, label="Choose model")
23
+ model_output = gr.HTML()
24
+ current_index = gr.State(value=0)
25
+ current_html = gr.State(value="")
26
+
27
+ def load_initial(model):
28
+ html = display_model_responses_html(evaluation_data, responses, model, 0)
29
+ return html, 5, html
30
+
31
+ def load_more(model, index, html_so_far):
32
+ new_html = display_model_responses_html(evaluation_data, responses, model, index)
33
+ updated_html = html_so_far + new_html
34
+ return updated_html, index + 5, updated_html
35
+
36
+ selected_model.change(load_initial, selected_model, [model_output, current_index, current_html])
37
+ demo.load(load_initial, inputs=selected_model, outputs=[model_output, current_index, current_html])
38
+
39
+ more_button = gr.Button("Load more")
40
+ more_button.click(load_more, inputs=[selected_model, current_index, current_html], outputs=[model_output, current_index, current_html])
41
+
42
+ default_category = evaluation_data[0]["category"]
43
+ default_example_id = evaluation_data[0]["id"]
44
+
45
+ with gr.Column(visible=False) as example_mode:
46
+ category = gr.Dropdown(
47
+ choices=list(set(ex["category"] for ex in evaluation_data)),
48
+ label="Category",
49
+ value=default_category
50
+ )
51
+ example = gr.Dropdown(
52
+ label="Example",
53
+ value=default_example_id,
54
+ choices=get_examples_by_category(evaluation_data, default_category)
55
+ )
56
+ example_display = gr.HTML()
57
+
58
+ category.change(lambda c: gr.update(choices=get_examples_by_category(evaluation_data, c)), category, example)
59
+ example.change(
60
+ fn=lambda ex_id: display_example_responses_html(evaluation_data, responses, models, ex_id),
61
+ inputs=example,
62
+ outputs=example_display
63
+ )
64
+
65
+ demo.load(fn=lambda: display_example_responses_html(evaluation_data, responses, models, default_example_id), inputs=None, outputs=example_display)
66
+
67
+ def switch_mode(selected):
68
+ return {
69
+ model_mode: gr.update(visible=selected == "View model-wise responses"),
70
+ example_mode: gr.update(visible=selected == "Compare model responses on a specific example"),
71
+ }
72
+
73
+ mode.change(switch_mode, mode, [model_mode, example_mode])
74
+ gr.HTML(r"""
75
+ <style>
76
+ #image-modal {
77
+ display: none;
78
+ position: fixed;
79
+ z-index: 999;
80
+ left: 0; top: 0;
81
+ width: 100%; height: 100%;
82
+ background-color: rgba(0, 0, 0, 0.8);
83
+ align-items: center;
84
+ justify-content: center;
85
+ }
86
+
87
+ #image-modal img {
88
+ max-width: 90%;
89
+ max-height: 90%;
90
+ border-radius: 8px;
91
+ box-shadow: 0 0 20px rgba(255,255,255,0.3);
92
+ }
93
+
94
+ #image-modal .close {
95
+ position: absolute;
96
+ top: 20px; right: 30px;
97
+ font-size: 32px;
98
+ color: #fff;
99
+ cursor: pointer;
100
+ font-weight: bold;
101
+ }
102
+ </style>
103
+
104
+ <div id="image-modal" onclick="closeModal(event)">
105
+ <span class="close" onclick="closeModal(event)">&times;</span>
106
+ <img id="modal-img" src="" alt="Enlarged Image" />
107
+ </div>
108
+
109
+ <script>
110
+ function openImage(src) {
111
+ const modal = document.getElementById('image-modal');
112
+ const img = document.getElementById('modal-img');
113
+ img.src = src;
114
+ modal.style.display = 'flex';
115
+ }
116
+
117
+ function closeModal(event) {
118
+ if (event.target.id === 'image-modal' || event.target.classList.contains('close')) {
119
+ document.getElementById('image-modal').style.display = 'none';
120
+ }
121
+ }
122
+
123
+ // Optional: close on ESC key
124
+ document.addEventListener('keydown', function(e) {
125
+ if (e.key === "Escape") {
126
+ document.getElementById('image-modal').style.display = 'none';
127
+ }
128
+ });
129
+ </script>
130
+ """)
131
+
132
+ demo.launch()