data-labeler / app.py
osbm's picture
app
e326f0c
raw
history blame
2.31 kB
import os
import streamlit as st
import pandas as pd
import numpy as np
import huggingface_hub as hfh
voters = [
"osman",
"eren",
"robin",
"mira",
"bilal",
"volunteer-1",
"volunteer-2",
"volunteer-3",
"volunteer-4",
"volunteer-5",
]
api = hfh.HfApi(token=os.environ.get("hf_token"))
# login page
with st.form("login"):
username = st.selectbox("Select voter", voters)
password = st.text_input("Password (get password from [email protected])", type="password")
submitted = st.form_submit_button("Login")
def get_list_of_images():
files = api.list_repo_tree(repo_id="aifred-smart-life-coach/capstone-images", repo_type="dataset", recursive=True,)
files = [file.path for file in files if file.path.endswith((".png", ".jpg"))]
return files
def get_one_from_queue(voter: str):
# get an image for the voter or return False if no image is left
# aifred-smart-life-coach/labels labels dataset
# labels dataset multiple csv files named as [voter name].csv
# each csv file has the image image path vote date, votes
files = api.list_repo_tree(repo_id="aifred-smart-life-coach/labels", repo_type="dataset", recursive=True,)
for file in files:
if file.path == f"{voter}.csv":
df = pd.read_csv(api.download_file(file.path))
print(df)
return None
if submitted:
if not password == os.environ.get("app_password"):
st.error("The password you entered is incorrect")
st.stop()
else:
st.success("Welcome, " + username)
st.write("You are now logged in")
with st.form("images"):
queue = get_one_from_queue(username)
if not queue:
st.write("You have voted for all the images")
st.stop()
st.image(queue["image"])
healthiness = st.slider("How healthy is this picture?", 0, 100, 50)
fat_level = st.slider("How fat is this picture?", 0, 100, 50)
muscle_level = st.slider("How muscular is this picture?", 0, 100, 50)
# Every form must have a submit button.
submitted = st.form_submit_button("Submit")
if submitted:
st.write("slideers", healthiness, fat_level, muscle_level)
# push the data to the database
st.write("Outside the form")