Miquel Farré
commited on
Commit
·
c993b98
1
Parent(s):
cd5f216
update
Browse files
app.py
CHANGED
@@ -13,63 +13,62 @@ MAX_RETRIES = 3
|
|
13 |
|
14 |
def commit_signup(username: str) -> Optional[str]:
|
15 |
"""Attempt to commit new signup atomically, always reading latest data before commit"""
|
16 |
-
|
17 |
# Always get the latest data right before committing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
try:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
filename="waitlist.csv",
|
23 |
-
token=os.getenv("HF_TOKEN")
|
24 |
)
|
25 |
-
current_data = pd.read_csv(file_content)
|
26 |
-
if 'userid' not in current_data.columns or 'joined_at' not in current_data.columns:
|
27 |
-
current_data = pd.DataFrame(columns=['userid', 'joined_at'])
|
28 |
except Exception as e:
|
29 |
-
print(f"
|
30 |
-
current_data = pd.DataFrame(columns=['userid', 'joined_at'])
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
return None
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
# Combine with latest data
|
43 |
-
updated_data = pd.concat([current_data, new_row], ignore_index=True)
|
44 |
-
|
45 |
-
# Save to temp file
|
46 |
-
with tempfile.NamedTemporaryFile(mode='w', suffix='.csv', delete=False) as tmp:
|
47 |
-
updated_data.to_csv(tmp.name, index=False)
|
48 |
-
|
49 |
-
try:
|
50 |
-
operation = CommitOperationAdd(
|
51 |
-
path_in_repo="waitlist.csv",
|
52 |
-
path_or_fileobj=tmp.name
|
53 |
-
)
|
54 |
-
except Exception as e:
|
55 |
-
print(f"CommitOperationAdd {str(e)}")
|
56 |
-
|
57 |
-
try:
|
58 |
-
create_commit(
|
59 |
-
repo_id=DATASET_REPO,
|
60 |
-
repo_type="dataset",
|
61 |
-
operations=[operation],
|
62 |
-
commit_message=f"Add user {username} to waitlist",
|
63 |
-
token=os.getenv("HF_TOKEN"),
|
64 |
-
)
|
65 |
-
os.unlink(tmp.name)
|
66 |
-
return None
|
67 |
-
except Exception as e:
|
68 |
-
print(f"Second error {str(e)}")
|
69 |
-
os.unlink(tmp.name)
|
70 |
-
return str(e)
|
71 |
-
except Exception as e:
|
72 |
-
return str(e)
|
73 |
|
74 |
def join_waitlist(
|
75 |
profile: gr.OAuthProfile | None,
|
|
|
13 |
|
14 |
def commit_signup(username: str) -> Optional[str]:
|
15 |
"""Attempt to commit new signup atomically, always reading latest data before commit"""
|
16 |
+
# try:
|
17 |
# Always get the latest data right before committing
|
18 |
+
try:
|
19 |
+
file_content = hf_api.hf_hub_download(
|
20 |
+
repo_id=DATASET_REPO,
|
21 |
+
repo_type="dataset",
|
22 |
+
filename="waitlist.csv",
|
23 |
+
token=os.getenv("HF_TOKEN")
|
24 |
+
)
|
25 |
+
current_data = pd.read_csv(file_content)
|
26 |
+
if 'userid' not in current_data.columns or 'joined_at' not in current_data.columns:
|
27 |
+
current_data = pd.DataFrame(columns=['userid', 'joined_at'])
|
28 |
+
except Exception as e:
|
29 |
+
print(f"First error {str(e)}")
|
30 |
+
current_data = pd.DataFrame(columns=['userid', 'joined_at'])
|
31 |
+
|
32 |
+
# If user already exists in the latest data, don't add them again
|
33 |
+
if username in current_data['userid'].values:
|
34 |
+
return None
|
35 |
+
|
36 |
+
# Add new user with timestamp
|
37 |
+
new_row = pd.DataFrame([{
|
38 |
+
'userid': username,
|
39 |
+
'joined_at': datetime.utcnow().isoformat()
|
40 |
+
}])
|
41 |
+
|
42 |
+
# Combine with latest data
|
43 |
+
updated_data = pd.concat([current_data, new_row], ignore_index=True)
|
44 |
+
|
45 |
+
# Save to temp file
|
46 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.csv', delete=False) as tmp:
|
47 |
+
updated_data.to_csv(tmp.name, index=False)
|
48 |
+
|
49 |
try:
|
50 |
+
operation = CommitOperationAdd(
|
51 |
+
path_in_repo="waitlist.csv",
|
52 |
+
path_or_fileobj=tmp.name
|
|
|
|
|
53 |
)
|
|
|
|
|
|
|
54 |
except Exception as e:
|
55 |
+
print(f"CommitOperationAdd {str(e)}")
|
|
|
56 |
|
57 |
+
try:
|
58 |
+
create_commit( repo_id=DATASET_REPO,
|
59 |
+
repo_type="dataset",
|
60 |
+
operations=[operation],
|
61 |
+
commit_message=f"Add user {username} to waitlist",
|
62 |
+
token=os.getenv("HF_TOKEN"),
|
63 |
+
)
|
64 |
+
os.unlink(tmp.name)
|
65 |
return None
|
66 |
+
except Exception as e:
|
67 |
+
print(f"Second error {str(e)}")
|
68 |
+
os.unlink(tmp.name)
|
69 |
+
return str(e)
|
70 |
+
# except Exception as e:
|
71 |
+
# return str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
def join_waitlist(
|
74 |
profile: gr.OAuthProfile | None,
|