Bit-Trading-Company commited on
Commit
98d7a3e
·
verified ·
1 Parent(s): bc0c291

CI deploy 8cef6a64

Browse files
Files changed (3) hide show
  1. app.py +15 -4
  2. src/ui/components.py +1 -1
  3. tests/test_ui.py +15 -0
app.py CHANGED
@@ -468,10 +468,21 @@ def build_app() -> gr.Blocks:
468
  # ------------------------- RIGHT -------------------------
469
  with gr.Column(scale=2, min_width=240):
470
  gr.HTML('<div class="bit-zone-title">Run Manager</div>')
471
- try:
472
- gr.LoginButton(value="Sign in with Hugging Face", size="sm")
473
- except Exception:
474
- gr.HTML(C.note("Sign-in appears when this runs on a Space."))
 
 
 
 
 
 
 
 
 
 
 
475
  history_html = gr.HTML(C.micro("no runs yet in this session"))
476
  with gr.Accordion("METRICS GLOSSARY", open=False,
477
  elem_classes="bit-accordion"):
 
468
  # ------------------------- RIGHT -------------------------
469
  with gr.Column(scale=2, min_width=240):
470
  gr.HTML('<div class="bit-zone-title">Run Manager</div>')
471
+ # Only construct the real OAuth button when running on a Space.
472
+ # Off-Space, Gradio "helpfully" mocks OAuth by calling HF's
473
+ # whoami, which raises without a token -- that would make the
474
+ # whole app unconstructable for anyone without credentials,
475
+ # even though reading and backtesting are meant to be open.
476
+ if os.environ.get("SPACE_ID"):
477
+ try:
478
+ gr.LoginButton(value="Sign in with Hugging Face", size="sm")
479
+ except Exception:
480
+ log.warning("LoginButton unavailable", exc_info=True)
481
+ gr.HTML(C.note("Sign-in is temporarily unavailable."))
482
+ else:
483
+ gr.HTML(C.note(
484
+ "Sign-in appears when this runs on a Hugging Face Space. "
485
+ "Reading and backtesting work without an account."))
486
  history_html = gr.HTML(C.micro("no runs yet in this session"))
487
  with gr.Accordion("METRICS GLOSSARY", open=False,
488
  elem_classes="bit-accordion"):
src/ui/components.py CHANGED
@@ -79,7 +79,7 @@ def footer() -> str:
79
  return f"""
80
  <div class="bit-footer">
81
  <span>{esc(config.DISCLAIMER)}</span>
82
- <span class="bit-footer-right">BITTRADING BACKTEST LAB v1.1.0</span>
83
  </div>"""
84
 
85
 
 
79
  return f"""
80
  <div class="bit-footer">
81
  <span>{esc(config.DISCLAIMER)}</span>
82
+ <span class="bit-footer-right">BITTRADING BACKTEST LAB v1.1.1</span>
83
  </div>"""
84
 
85
 
tests/test_ui.py CHANGED
@@ -416,3 +416,18 @@ def test_fonts_are_served_for_every_weight_the_design_uses():
416
  css = theme.full_css()
417
  assert css.count("@font-face") >= 5
418
  assert "Styrene A" in css and "Mac Minecraft" in css
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
416
  css = theme.full_css()
417
  assert css.count("@font-face") >= 5
418
  assert "Styrene A" in css and "Mac Minecraft" in css
419
+
420
+
421
+ def test_app_constructs_without_any_hugging_face_credentials(monkeypatch):
422
+ """Reading and backtesting are open to anyone, so the app must build with
423
+ no token at all. Gradio's off-Space OAuth mock calls whoami and raises
424
+ without one, which previously made the whole app unconstructable."""
425
+ import importlib
426
+
427
+ for var in ("HF_TOKEN", "HF_WRITE_TOKEN", "HUGGING_FACE_HUB_TOKEN", "SPACE_ID"):
428
+ monkeypatch.delenv(var, raising=False)
429
+
430
+ import app as fresh
431
+
432
+ importlib.reload(fresh)
433
+ assert fresh.demo is not None