update
Browse files
app.py
CHANGED
@@ -26,36 +26,28 @@ def commit_signup(username: str) -> Optional[str]:
|
|
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 |
-
print("we make it here")
|
32 |
# If user already exists in the latest data, don't add them again
|
33 |
if username in current_data['userid'].values:
|
34 |
-
return
|
35 |
|
36 |
# Add new user with timestamp
|
37 |
new_row = pd.DataFrame([{
|
38 |
'userid': username,
|
39 |
'joined_at': datetime.utcnow().isoformat()
|
40 |
}])
|
41 |
-
print("new row")
|
42 |
|
43 |
# Combine with latest data
|
44 |
updated_data = pd.concat([current_data, new_row], ignore_index=True)
|
45 |
-
print("updated data")
|
46 |
|
47 |
# Save to temp file
|
48 |
with tempfile.NamedTemporaryFile(mode='w', suffix='.csv', delete=False) as tmp:
|
49 |
updated_data.to_csv(tmp.name, index=False)
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
)
|
56 |
-
except Exception as e:
|
57 |
-
print(f"CommitOperationAdd {str(e)}")
|
58 |
-
print("commit operation")
|
59 |
|
60 |
try:
|
61 |
create_commit(
|
@@ -65,11 +57,9 @@ def commit_signup(username: str) -> Optional[str]:
|
|
65 |
commit_message=f"Add user {username} to waitlist",
|
66 |
token=os.getenv("HF_TOKEN"),
|
67 |
)
|
68 |
-
print("commit created")
|
69 |
os.unlink(tmp.name)
|
70 |
return None
|
71 |
except Exception as e:
|
72 |
-
print(f"Second error {str(e)}")
|
73 |
os.unlink(tmp.name)
|
74 |
return str(e)
|
75 |
except Exception as e:
|
@@ -91,6 +81,11 @@ def join_waitlist(
|
|
91 |
# Try to commit the update (which will get latest data internally)
|
92 |
error = commit_signup(username)
|
93 |
|
|
|
|
|
|
|
|
|
|
|
94 |
if error is None: # Success or already registered
|
95 |
# Verify user is in the list
|
96 |
file_content = hf_api.hf_hub_download(
|
|
|
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 |
current_data = pd.DataFrame(columns=['userid', 'joined_at'])
|
|
|
30 |
# If user already exists in the latest data, don't add them again
|
31 |
if username in current_data['userid'].values:
|
32 |
+
return "exist"
|
33 |
|
34 |
# Add new user with timestamp
|
35 |
new_row = pd.DataFrame([{
|
36 |
'userid': username,
|
37 |
'joined_at': datetime.utcnow().isoformat()
|
38 |
}])
|
|
|
39 |
|
40 |
# Combine with latest data
|
41 |
updated_data = pd.concat([current_data, new_row], ignore_index=True)
|
|
|
42 |
|
43 |
# Save to temp file
|
44 |
with tempfile.NamedTemporaryFile(mode='w', suffix='.csv', delete=False) as tmp:
|
45 |
updated_data.to_csv(tmp.name, index=False)
|
46 |
|
47 |
+
operation = CommitOperationAdd(
|
48 |
+
path_in_repo="waitlist.csv",
|
49 |
+
path_or_fileobj=tmp.name
|
50 |
+
)
|
|
|
|
|
|
|
|
|
51 |
|
52 |
try:
|
53 |
create_commit(
|
|
|
57 |
commit_message=f"Add user {username} to waitlist",
|
58 |
token=os.getenv("HF_TOKEN"),
|
59 |
)
|
|
|
60 |
os.unlink(tmp.name)
|
61 |
return None
|
62 |
except Exception as e:
|
|
|
63 |
os.unlink(tmp.name)
|
64 |
return str(e)
|
65 |
except Exception as e:
|
|
|
81 |
# Try to commit the update (which will get latest data internally)
|
82 |
error = commit_signup(username)
|
83 |
|
84 |
+
if error == "exist":
|
85 |
+
return gr.update(
|
86 |
+
value="## You are already in our waitlist, we will come back with news soon!",
|
87 |
+
visible=True
|
88 |
+
)
|
89 |
if error is None: # Success or already registered
|
90 |
# Verify user is in the list
|
91 |
file_content = hf_api.hf_hub_download(
|