Spaces:
Running
Running
Big images visualizer (#7)
Browse files- Big image visualizer (553315420a4b4c08d112af0f61dc7a9181f0ae26)
- app.py +25 -4
- data_utils.py +11 -22
- utils.py +6 -8
app.py
CHANGED
|
@@ -25,6 +25,22 @@ def filter_models_by_param(min_params):
|
|
| 25 |
selected = filtered_models[0] if filtered_models else None
|
| 26 |
return gr.update(choices=filtered_models, value=selected)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
models = list(model_params.keys())
|
| 29 |
|
| 30 |
default_category = evaluation_data[0]["category"]
|
|
@@ -39,6 +55,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 39 |
with gr.Column(visible=True) as model_mode:
|
| 40 |
param_slider = gr.Slider(minimum=2, maximum=32, step=1, label="Minimum model parameters (B)")
|
| 41 |
selected_model = gr.Dropdown(models, label="Choose model")
|
|
|
|
| 42 |
|
| 43 |
param_slider.change(filter_models_by_param, inputs=param_slider, outputs=selected_model)
|
| 44 |
model_category = gr.Dropdown(
|
|
@@ -54,7 +71,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 54 |
filtered_data = [ex for ex in evaluation_data if ex["category"] == category]
|
| 55 |
html = display_model_responses_html(evaluation_data, responses, model, start_index=0, batch_size=5, category=category)
|
| 56 |
has_more = 5 < len(filtered_data)
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
def load_more(model, index, html_so_far, category):
|
|
@@ -74,18 +94,18 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 74 |
selected_model.change(
|
| 75 |
load_initial,
|
| 76 |
inputs=[selected_model, model_category],
|
| 77 |
-
outputs=[model_output, current_index, current_html, more_button]
|
| 78 |
)
|
| 79 |
model_category.change(
|
| 80 |
load_initial,
|
| 81 |
inputs=[selected_model, model_category],
|
| 82 |
-
outputs=[model_output, current_index, current_html, more_button]
|
| 83 |
)
|
| 84 |
|
| 85 |
demo.load(
|
| 86 |
load_initial,
|
| 87 |
inputs=[selected_model, model_category],
|
| 88 |
-
outputs=[model_output, current_index, current_html, more_button]
|
| 89 |
)
|
| 90 |
|
| 91 |
more_button.click(
|
|
@@ -155,6 +175,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 155 |
<span class="close" onclick="closeModal(event)">×</span>
|
| 156 |
<img id="modal-img" src="" alt="Enlarged Image" />
|
| 157 |
</div>
|
|
|
|
| 158 |
<script>
|
| 159 |
function openImage(src) {
|
| 160 |
const modal = document.getElementById('image-modal');
|
|
|
|
| 25 |
selected = filtered_models[0] if filtered_models else None
|
| 26 |
return gr.update(choices=filtered_models, value=selected)
|
| 27 |
|
| 28 |
+
def display_model_details(model_name):
|
| 29 |
+
if model_name not in model_params:
|
| 30 |
+
return "No info available."
|
| 31 |
+
|
| 32 |
+
size = model_params[model_name]
|
| 33 |
+
provider = model_name.split("/")[0] if "/" in model_name else "Unknown"
|
| 34 |
+
link = f"https://huggingface.co/{model_name}"
|
| 35 |
+
|
| 36 |
+
return f"""
|
| 37 |
+
<div style="margin-top: 10px; font-size: 15px;">
|
| 38 |
+
<p><strong>Provider:</strong> {provider}</p>
|
| 39 |
+
<p><strong>Size:</strong> {size}B</p>
|
| 40 |
+
<p><strong>Link:</strong> <a href="{link}" target="_blank">{link}</a></p>
|
| 41 |
+
</div>
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
models = list(model_params.keys())
|
| 45 |
|
| 46 |
default_category = evaluation_data[0]["category"]
|
|
|
|
| 55 |
with gr.Column(visible=True) as model_mode:
|
| 56 |
param_slider = gr.Slider(minimum=2, maximum=32, step=1, label="Minimum model parameters (B)")
|
| 57 |
selected_model = gr.Dropdown(models, label="Choose model")
|
| 58 |
+
model_info_box = gr.HTML()
|
| 59 |
|
| 60 |
param_slider.change(filter_models_by_param, inputs=param_slider, outputs=selected_model)
|
| 61 |
model_category = gr.Dropdown(
|
|
|
|
| 71 |
filtered_data = [ex for ex in evaluation_data if ex["category"] == category]
|
| 72 |
html = display_model_responses_html(evaluation_data, responses, model, start_index=0, batch_size=5, category=category)
|
| 73 |
has_more = 5 < len(filtered_data)
|
| 74 |
+
|
| 75 |
+
model_info_html = display_model_details(model)
|
| 76 |
+
|
| 77 |
+
return html, 5, html, gr.update(visible=has_more), model_info_html
|
| 78 |
|
| 79 |
|
| 80 |
def load_more(model, index, html_so_far, category):
|
|
|
|
| 94 |
selected_model.change(
|
| 95 |
load_initial,
|
| 96 |
inputs=[selected_model, model_category],
|
| 97 |
+
outputs=[model_output, current_index, current_html, more_button, model_info_box]
|
| 98 |
)
|
| 99 |
model_category.change(
|
| 100 |
load_initial,
|
| 101 |
inputs=[selected_model, model_category],
|
| 102 |
+
outputs=[model_output, current_index, current_html, more_button, model_info_box]
|
| 103 |
)
|
| 104 |
|
| 105 |
demo.load(
|
| 106 |
load_initial,
|
| 107 |
inputs=[selected_model, model_category],
|
| 108 |
+
outputs=[model_output, current_index, current_html, more_button, model_info_box]
|
| 109 |
)
|
| 110 |
|
| 111 |
more_button.click(
|
|
|
|
| 175 |
<span class="close" onclick="closeModal(event)">×</span>
|
| 176 |
<img id="modal-img" src="" alt="Enlarged Image" />
|
| 177 |
</div>
|
| 178 |
+
|
| 179 |
<script>
|
| 180 |
function openImage(src) {
|
| 181 |
const modal = document.getElementById('image-modal');
|
data_utils.py
CHANGED
|
@@ -5,28 +5,17 @@ from utils import *
|
|
| 5 |
def get_evaluation_data(ds):
|
| 6 |
evaluation_data = []
|
| 7 |
for i in range(len(ds)):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
})
|
| 20 |
-
except (UnidentifiedImageError, OSError, ValueError): # To handle .heic images -> can be removed when dataset is fixed
|
| 21 |
-
img = Image.new("RGB", (256, 256), color="white")
|
| 22 |
-
evaluation_data.append({
|
| 23 |
-
"id": i,
|
| 24 |
-
"image_thumbnail": image_to_base64(img),
|
| 25 |
-
"image_full": image_to_base64(img),
|
| 26 |
-
"image_full_url": "https://huggingface.co/", # Dummy
|
| 27 |
-
"prompt": "Dummy prompt",
|
| 28 |
-
"category": "Dummy category"
|
| 29 |
-
})
|
| 30 |
return evaluation_data
|
| 31 |
|
| 32 |
def get_model_names(ds_results):
|
|
|
|
| 5 |
def get_evaluation_data(ds):
|
| 6 |
evaluation_data = []
|
| 7 |
for i in range(len(ds)):
|
| 8 |
+
img = ds[i]["image"]
|
| 9 |
+
thumbnail_img = img.copy()
|
| 10 |
+
thumbnail_img.thumbnail((256, 256))
|
| 11 |
+
evaluation_data.append({
|
| 12 |
+
"id": ds[i]["ex_id"],
|
| 13 |
+
"image_thumbnail": image_to_base64(thumbnail_img),
|
| 14 |
+
"image_full": image_to_base64(img),
|
| 15 |
+
"image_full_url": "https://sergiopaniego-vibe-testing-images.hf.space/image/" + str(i),
|
| 16 |
+
"prompt": ds[i]["prompt"],
|
| 17 |
+
"category": ds[i]["category"]
|
| 18 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
return evaluation_data
|
| 20 |
|
| 21 |
def get_model_names(ds_results):
|
utils.py
CHANGED
|
@@ -31,10 +31,9 @@ def display_model_responses_html(evaluation_data, responses, model, start_index=
|
|
| 31 |
|
| 32 |
html += f"""
|
| 33 |
<div style="display: flex; margin-bottom: 20px; align-items: flex-start;">
|
| 34 |
-
<
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
</a>
|
| 38 |
<div style="flex: 1; background-color: var(--block-background-fill); padding: 16px 20px; border-radius: 12px;
|
| 39 |
font-family: 'Segoe UI', sans-serif; box-shadow: 0 2px 6px rgba(0,0,0,0.05);">
|
| 40 |
<p style="margin: 0 0 10px; font-size: 14px; color: var(--secondary-text-color);">
|
|
@@ -69,10 +68,9 @@ def display_example_responses_html(evaluation_data, responses, models, example_i
|
|
| 69 |
|
| 70 |
html = f"""
|
| 71 |
<div style="display: flex; margin-bottom: 20px; align-items: flex-start;">
|
| 72 |
-
<
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
</a>
|
| 76 |
<div style="flex: 1; background-color: var(--block-background-fill); padding: 16px 20px; border-radius: 12px;
|
| 77 |
font-family: 'Segoe UI', sans-serif; box-shadow: 0 2px 6px rgba(0,0,0,0.05);">
|
| 78 |
<p style="margin: 0 0 10px; font-size: 14px; color: var(--secondary-text-color);">
|
|
|
|
| 31 |
|
| 32 |
html += f"""
|
| 33 |
<div style="display: flex; margin-bottom: 20px; align-items: flex-start;">
|
| 34 |
+
<img src="data:image/png;base64,{image_thumbnail}" alt="Example Image"
|
| 35 |
+
style="height: 200px; margin-right: 20px; border-radius: 8px; cursor: zoom-in;"
|
| 36 |
+
onclick="openImage('{image_full_url}')" />
|
|
|
|
| 37 |
<div style="flex: 1; background-color: var(--block-background-fill); padding: 16px 20px; border-radius: 12px;
|
| 38 |
font-family: 'Segoe UI', sans-serif; box-shadow: 0 2px 6px rgba(0,0,0,0.05);">
|
| 39 |
<p style="margin: 0 0 10px; font-size: 14px; color: var(--secondary-text-color);">
|
|
|
|
| 68 |
|
| 69 |
html = f"""
|
| 70 |
<div style="display: flex; margin-bottom: 20px; align-items: flex-start;">
|
| 71 |
+
<img src="data:image/png;base64,{image_thumbnail}" alt="Example Image"
|
| 72 |
+
style="height: 200px; margin-right: 20px; border-radius: 8px; cursor: zoom-in;"
|
| 73 |
+
onclick="openImage('{image_full_url}')" />
|
|
|
|
| 74 |
<div style="flex: 1; background-color: var(--block-background-fill); padding: 16px 20px; border-radius: 12px;
|
| 75 |
font-family: 'Segoe UI', sans-serif; box-shadow: 0 2px 6px rgba(0,0,0,0.05);">
|
| 76 |
<p style="margin: 0 0 10px; font-size: 14px; color: var(--secondary-text-color);">
|