Spaces:
Sleeping
Sleeping
refactor update_vote function to streamline image voting process and improve login handling
Browse files
app.py
CHANGED
|
@@ -74,14 +74,7 @@ def update_vote(
|
|
| 74 |
|
| 75 |
df = pd.read_csv(file_path)
|
| 76 |
print(df)
|
| 77 |
-
num_past_votes = df.shape[0]
|
| 78 |
-
print("num_past_votes", num_past_votes)
|
| 79 |
|
| 80 |
-
# get the list of images that are not present in the csv file
|
| 81 |
-
images_not_voted = list(set(list_of_images) - set(df["image_path"].tolist()))
|
| 82 |
-
print("images_not_voted", len(images_not_voted))
|
| 83 |
-
|
| 84 |
-
# update the csv file with the new vote
|
| 85 |
new_row = {
|
| 86 |
"image_path": image,
|
| 87 |
"healthiness": healthiness,
|
|
@@ -94,44 +87,29 @@ def update_vote(
|
|
| 94 |
# push the file to the dataset
|
| 95 |
api.push_to_hub(file_path, repo_id="aifred-smart-life-coach/labels", repo_type="dataset", commit_message=f"Voted for {image}")
|
| 96 |
|
| 97 |
-
print(get_one_from_queue("osman"))
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
if 'loggedin' not in st.session_state:
|
| 102 |
st.session_state['loggedin'] = 'false'
|
| 103 |
|
| 104 |
-
# login page
|
| 105 |
with st.form("login"):
|
| 106 |
username = st.selectbox("Select voter", voters)
|
| 107 |
password = st.text_input("Password (get password from contact@osbm.dev)", type="password")
|
| 108 |
submitted = st.form_submit_button("Login")
|
| 109 |
|
| 110 |
-
# save the logged in status on the machine
|
| 111 |
-
|
| 112 |
if submitted or st.session_state['loggedin'] == 'true':
|
| 113 |
-
st.session_state['loggedin'] = 'true'
|
| 114 |
-
|
| 115 |
if not password == os.environ.get("app_password"):
|
| 116 |
st.error("The password you entered is incorrect")
|
| 117 |
st.stop()
|
| 118 |
else:
|
| 119 |
st.success("Welcome, " + username)
|
| 120 |
st.write("You are now logged in")
|
|
|
|
|
|
|
| 121 |
|
| 122 |
with st.form("images"):
|
| 123 |
image_path = get_one_from_queue(username)
|
| 124 |
if not image_path:
|
| 125 |
st.write("You have voted for all the images")
|
| 126 |
st.stop()
|
| 127 |
-
# https://huggingface.co/datasets/aifred-smart-life-coach/capstone-images/resolve/main/kaggle-human-segmentation-dataset/Women%20I/img/woman_image_200.jpg
|
| 128 |
-
# print(image_path)
|
| 129 |
-
# image_url = f"https://huggingface.co/datasets/aifred-smart-life-coach/capstone-images/resolve/main/{image_path}"
|
| 130 |
-
# # url has whitespace, replace it with %20
|
| 131 |
-
# image_url = image_url.replace(" ", "%20")
|
| 132 |
-
# print(image_url)
|
| 133 |
-
# st.image(image_url, width=300)
|
| 134 |
-
# st.markdown(f'<img src="{image_url}">', unsafe_allow_html=True)
|
| 135 |
|
| 136 |
path = hfh.hf_hub_download(repo_id="aifred-smart-life-coach/capstone-images", repo_type="dataset",filename=image_path, token=os.environ.get("hf_token"))
|
| 137 |
st.image(path, width=300)
|
|
@@ -146,7 +124,6 @@ if submitted or st.session_state['loggedin'] == 'true':
|
|
| 146 |
# Every form must have a submit button.
|
| 147 |
submitted_second = st.form_submit_button("Submit")
|
| 148 |
|
| 149 |
-
|
| 150 |
if submitted_second:
|
| 151 |
update_vote(username, image_path, healthiness, fat_level, muscle_level)
|
| 152 |
st.write("Vote submitted")
|
|
|
|
| 74 |
|
| 75 |
df = pd.read_csv(file_path)
|
| 76 |
print(df)
|
|
|
|
|
|
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
new_row = {
|
| 79 |
"image_path": image,
|
| 80 |
"healthiness": healthiness,
|
|
|
|
| 87 |
# push the file to the dataset
|
| 88 |
api.push_to_hub(file_path, repo_id="aifred-smart-life-coach/labels", repo_type="dataset", commit_message=f"Voted for {image}")
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
if 'loggedin' not in st.session_state:
|
| 91 |
st.session_state['loggedin'] = 'false'
|
| 92 |
|
|
|
|
| 93 |
with st.form("login"):
|
| 94 |
username = st.selectbox("Select voter", voters)
|
| 95 |
password = st.text_input("Password (get password from contact@osbm.dev)", type="password")
|
| 96 |
submitted = st.form_submit_button("Login")
|
| 97 |
|
|
|
|
|
|
|
| 98 |
if submitted or st.session_state['loggedin'] == 'true':
|
|
|
|
|
|
|
| 99 |
if not password == os.environ.get("app_password"):
|
| 100 |
st.error("The password you entered is incorrect")
|
| 101 |
st.stop()
|
| 102 |
else:
|
| 103 |
st.success("Welcome, " + username)
|
| 104 |
st.write("You are now logged in")
|
| 105 |
+
st.session_state['loggedin'] = 'true'
|
| 106 |
+
|
| 107 |
|
| 108 |
with st.form("images"):
|
| 109 |
image_path = get_one_from_queue(username)
|
| 110 |
if not image_path:
|
| 111 |
st.write("You have voted for all the images")
|
| 112 |
st.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
path = hfh.hf_hub_download(repo_id="aifred-smart-life-coach/capstone-images", repo_type="dataset",filename=image_path, token=os.environ.get("hf_token"))
|
| 115 |
st.image(path, width=300)
|
|
|
|
| 124 |
# Every form must have a submit button.
|
| 125 |
submitted_second = st.form_submit_button("Submit")
|
| 126 |
|
|
|
|
| 127 |
if submitted_second:
|
| 128 |
update_vote(username, image_path, healthiness, fat_level, muscle_level)
|
| 129 |
st.write("Vote submitted")
|