Spaces:
Sleeping
Sleeping
add following features: update dropdowns after each rank submission, save the results at the end of the form in the dataset hub
da0e039
| import os | |
| import pandas as pd | |
| from huggingface_hub import HfApi, HfFolder | |
| import yaml | |
| import numpy as np | |
| import time | |
| config = yaml.safe_load(open("./config/config.yaml")) | |
| def load_image_and_saliency(class_idx, data_dir): | |
| path = os.path.join(data_dir, 'images', str(class_idx)) | |
| images = os.listdir(path) | |
| # pick a random image | |
| id = np.random.randint(0, len(images)) | |
| image = os.path.join(path, images[id]) | |
| gradcam_image = os.path.join(data_dir, 'saliency', 'gradcam', images[id]) | |
| lime_image = os.path.join(data_dir, 'saliency', 'lime', images[id]) | |
| sidu_image = os.path.join(data_dir, 'saliency', 'sidu', images[id]) | |
| rise_image = os.path.join(data_dir, 'saliency', 'rise', images[id]) | |
| return image, gradcam_image, lime_image, sidu_image, rise_image | |
| def load_example_images(class_idx, data_dir, max_images=16): | |
| path = os.path.join(data_dir, 'images', str(class_idx)) | |
| images = os.listdir(path) | |
| # pick max_images random images | |
| ids = np.random.choice(len(images), max_images, replace=False) | |
| images = [os.path.join(path, images[id]) for id in ids] | |
| return images | |
| # Function to load words based on global variable | |
| def load_words(idx): | |
| words = [f"word_{idx}_{i}" for i in range(20)] | |
| return words | |