Update app.py
Browse files
app.py
CHANGED
|
@@ -76,7 +76,36 @@ def submit_form(email, team, affiliation, student, oauth_token: gr.OAuthToken =
|
|
| 76 |
|
| 77 |
return "Registration successful!"
|
| 78 |
|
|
|
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
with gr.Blocks() as demo:
|
| 82 |
gr.Markdown("### Registration Form (HuggingFace login required)")
|
|
@@ -116,6 +145,11 @@ with gr.Blocks() as demo:
|
|
| 116 |
inputs=[email, team, affiliation, student],
|
| 117 |
outputs=output
|
| 118 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
|
| 121 |
demo.launch()
|
|
|
|
| 76 |
|
| 77 |
return "Registration successful!"
|
| 78 |
|
| 79 |
+
return "Registration successful!"
|
| 80 |
|
| 81 |
+
# Function to check registration status
|
| 82 |
+
def check_registration(gr.OAuthToken = None):
|
| 83 |
+
if oauth_token is None or oauth_token.token is None:
|
| 84 |
+
raise gr.Error("You must be logged in to register!")
|
| 85 |
+
|
| 86 |
+
user_info = api.whoami(token=oauth_token.token)
|
| 87 |
+
hf_user_id = user_info['name']
|
| 88 |
+
|
| 89 |
+
local_dir = snapshot_download(
|
| 90 |
+
repo_id=DATASET_REPO,
|
| 91 |
+
repo_type="dataset",
|
| 92 |
+
use_auth_token=hf_token,
|
| 93 |
+
local_dir=tempfile.mkdtemp(),
|
| 94 |
+
local_dir_use_symlinks=False
|
| 95 |
+
)
|
| 96 |
+
dataset_path = os.path.join(local_dir, DATASET_FILE)
|
| 97 |
+
|
| 98 |
+
if os.path.exists(dataset_path):
|
| 99 |
+
with open(dataset_path, "r") as f:
|
| 100 |
+
data = json.load(f)
|
| 101 |
+
else:
|
| 102 |
+
data = []
|
| 103 |
+
|
| 104 |
+
for entry in data:
|
| 105 |
+
if entry["hf_id"] == hf_user_id:
|
| 106 |
+
return f"✅ You are registered in team: **{entry['team']}**"
|
| 107 |
+
|
| 108 |
+
return "❌ You are not registered yet."
|
| 109 |
|
| 110 |
with gr.Blocks() as demo:
|
| 111 |
gr.Markdown("### Registration Form (HuggingFace login required)")
|
|
|
|
| 145 |
inputs=[email, team, affiliation, student],
|
| 146 |
outputs=output
|
| 147 |
)
|
| 148 |
+
check_btn = gr.Button("Check Registration Status")
|
| 149 |
+
check_btn.click(
|
| 150 |
+
fn=check_registration,
|
| 151 |
+
outputs=output
|
| 152 |
+
)
|
| 153 |
|
| 154 |
|
| 155 |
demo.launch()
|