|
|
import altair as alt |
|
|
import numpy as np |
|
|
import pandas as pd |
|
|
import streamlit as st |
|
|
|
|
|
import uuid |
|
|
from pathlib import Path |
|
|
from huggingface_hub import CommitScheduler |
|
|
import json |
|
|
|
|
|
from huggingface_hub import whoami |
|
|
import os |
|
|
|
|
|
import datetime |
|
|
|
|
|
user = whoami(token=os.environ.get("HF_TOKEN")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feedback_folder = Path("data_JSON") |
|
|
feedback_folder.mkdir(parents=True, exist_ok=True) |
|
|
feedback_file = feedback_folder / f"data_{uuid.uuid4()}.json" |
|
|
|
|
|
|
|
|
scheduler = CommitScheduler( |
|
|
repo_id="data_pref", |
|
|
repo_type="dataset", |
|
|
folder_path=feedback_folder, |
|
|
path_in_repo="data", |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'cont_r' not in st.session_state: |
|
|
st.session_state.cont_r = 0 |
|
|
|
|
|
|
|
|
|
|
|
st.set_page_config(page_title="Image Preference Study", layout="centered") |
|
|
|
|
|
st.title("Image Preference Study") |
|
|
|
|
|
st.header("Instructions", divider=True) |
|
|
|
|
|
st.markdown(f"You will be shown 25 pairs of images. For each pair, please select which image \"Option A\" (left) or \"Option B\" (right) you think is \ |
|
|
**more visually appealing** and has a **better quality** (for example, *sharp edges*, *clear object details/shapes/proportions*, etc.), regardless of the picture subject content.") |
|
|
st.markdown(f"Please, evaluate each pair of images **independently** of the other pairs.") |
|
|
st.markdown(f"If needed, please, look closer to the screen and/or zoom in the pictures.") |
|
|
st.markdown(f"*Example: If Option A depicts a gray bunny and is a better quality picture than Option B which depicts a brown bunny, I would choose Option A despite \ |
|
|
the fact that I personally *like* brown bunnies more than gray bunnies.*") |
|
|
|
|
|
st.header("Images", divider=True) |
|
|
|
|
|
|
|
|
image_pairs = [ |
|
|
("images/A_0.jpeg", "images/B_0.jpeg"), |
|
|
("images/A_1.jpeg", "images/B_1.jpeg"), |
|
|
("images/A_2.jpeg", "images/B_2.jpeg"), |
|
|
("images/A_3.jpeg", "images/B_3.jpeg"), |
|
|
("images/A_4.jpeg", "images/B_4.jpeg"), |
|
|
("images/A_5.jpeg", "images/B_5.jpeg"), |
|
|
("images/A_6.jpeg", "images/B_6.jpeg"), |
|
|
("images/A_7.jpeg", "images/B_7.jpeg"), |
|
|
("images/A_8.jpeg", "images/B_8.jpeg"), |
|
|
("images/A_9.jpeg", "images/B_9.jpeg"), |
|
|
("images/A_10.jpeg", "images/B_10.jpeg"), |
|
|
("images/A_11.jpeg", "images/B_11.jpeg"), |
|
|
("images/A_12.jpeg", "images/B_12.jpeg"), |
|
|
("images/A_13.jpeg", "images/B_13.jpeg"), |
|
|
("images/A_14.jpeg", "images/B_14.jpeg"), |
|
|
("images/A_15.jpeg", "images/B_15.jpeg"), |
|
|
("images/A_16.jpeg", "images/B_16.jpeg"), |
|
|
("images/A_17.jpeg", "images/B_17.jpeg"), |
|
|
("images/A_18.jpeg", "images/B_18.jpeg"), |
|
|
("images/A_19.jpeg", "images/B_19.jpeg"), |
|
|
("images/A_20.jpeg", "images/B_20.jpeg"), |
|
|
("images/A_21.jpeg", "images/B_21.jpeg"), |
|
|
("images/A_22.jpeg", "images/B_22.jpeg"), |
|
|
("images/A_23.jpeg", "images/B_23.jpeg"), |
|
|
("images/A_24.jpeg", "images/B_24.jpeg") |
|
|
] |
|
|
|
|
|
results = {} |
|
|
|
|
|
|
|
|
code_prov = st.text_input("Type the provided code in the box below:") |
|
|
|
|
|
|
|
|
for i, (imgA, imgB) in enumerate(image_pairs): |
|
|
st.markdown(f"### Pair {i+1}") |
|
|
col1, col2 = st.columns(2) |
|
|
|
|
|
with col1: |
|
|
st.image(imgA, caption="Option A", use_container_width=True) |
|
|
with col2: |
|
|
st.image(imgB, caption="Option B", use_container_width=True) |
|
|
|
|
|
choice = st.radio( |
|
|
f"Which image do you prefer for Pair {i+1}?", |
|
|
("-","Option A (left)", "Option B (right)"), |
|
|
key=f"choice_{i}" |
|
|
) |
|
|
results[f"pair_{i+1}"] = choice |
|
|
|
|
|
|
|
|
if st.button("Submit"): |
|
|
|
|
|
cont = 0 |
|
|
for key in results: |
|
|
if results[key] == "-": |
|
|
cont += 1 |
|
|
|
|
|
if code_prov == "": |
|
|
st.error("Please, insert your provided code at the beginning of this form. Then, try submitting again.") |
|
|
elif cont != 0: |
|
|
st.error("It seems you have not evaluated all pairs. Please, check again and Submit. Click on Submit again if you think there is error.") |
|
|
else: |
|
|
if st.session_state.cont_r == 0: |
|
|
|
|
|
st.session_state.cont_r += 1 |
|
|
|
|
|
|
|
|
st.success("Thank you! Your selection has been recorded.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current_time = datetime.datetime.now() |
|
|
results["day"] = str(current_time.day) |
|
|
results["time"] = str(current_time.hour) + ":" + str(current_time.minute) + ":" + str(current_time.second) |
|
|
results["code"] = code_prov |
|
|
results["page"] = "Im_2" |
|
|
|
|
|
with scheduler.lock: |
|
|
with feedback_file.open("a") as f: |
|
|
f.write(json.dumps(results)) |
|
|
f.write("\n") |
|
|
|
|
|
else: |
|
|
st.success("Thanks. Only one submission is allowed.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|