Spaces:
Sleeping
Sleeping
add error handling for duplicate image votes and fix DataFrame concatenation
Browse files
app.py
CHANGED
|
@@ -80,6 +80,11 @@ def update_vote(
|
|
| 80 |
df = pd.read_csv(file_path)
|
| 81 |
print(df)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
new_row = pd.DataFrame(
|
| 84 |
{
|
| 85 |
"image_path": [image],
|
|
@@ -92,7 +97,7 @@ def update_vote(
|
|
| 92 |
}
|
| 93 |
)
|
| 94 |
|
| 95 |
-
df =
|
| 96 |
df.to_csv(file_path, index=False)
|
| 97 |
|
| 98 |
# push the file to the dataset
|
|
|
|
| 80 |
df = pd.read_csv(file_path)
|
| 81 |
print(df)
|
| 82 |
|
| 83 |
+
# if the df has the image path of the image, raise an error
|
| 84 |
+
if image in df["image_path"].tolist():
|
| 85 |
+
st.error("You have already voted for this image")
|
| 86 |
+
st.stop()
|
| 87 |
+
|
| 88 |
new_row = pd.DataFrame(
|
| 89 |
{
|
| 90 |
"image_path": [image],
|
|
|
|
| 97 |
}
|
| 98 |
)
|
| 99 |
|
| 100 |
+
df = pd.concat([df, new_row], ignore_index=True)
|
| 101 |
df.to_csv(file_path, index=False)
|
| 102 |
|
| 103 |
# push the file to the dataset
|