LinJennyLin commited on
Commit
b4ad4b9
·
verified ·
1 Parent(s): ffbe64b

Upload webapp/app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. webapp/app.py +22 -0
webapp/app.py CHANGED
@@ -321,6 +321,28 @@ def _persist_subscriber(email: str, ts: str) -> None:
321
  pass
322
 
323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  @app.route("/subscribe", methods=["POST"])
325
  def subscribe():
326
  email = (request.form.get("email") or "").strip().lower()
 
321
  pass
322
 
323
 
324
+ @app.route("/_diag")
325
+ def _diag():
326
+ import io
327
+ tok = os.environ.get("HF_TOKEN")
328
+ out = [f"HF_TOKEN present: {bool(tok)}", f"len: {len(tok) if tok else 0}"]
329
+ try:
330
+ from huggingface_hub import HfApi
331
+ out.append("huggingface_hub import: OK")
332
+ if tok:
333
+ try:
334
+ HfApi(token=tok).upload_file(
335
+ path_or_fileobj=io.BytesIO(b"diag,now\n"),
336
+ path_in_repo="emails/_diag.csv",
337
+ repo_id=SUBSCRIBERS_DATASET, repo_type="dataset")
338
+ out.append("dataset write: OK")
339
+ except Exception as e:
340
+ out.append(f"dataset write FAILED: {type(e).__name__}: {str(e)[:200]}")
341
+ except Exception as e:
342
+ out.append(f"hub import FAILED: {type(e).__name__}: {e}")
343
+ return "<pre>" + escape("\n".join(out)) + "</pre>"
344
+
345
+
346
  @app.route("/subscribe", methods=["POST"])
347
  def subscribe():
348
  email = (request.form.get("email") or "").strip().lower()