YugJ commited on
Commit
9c74cc3
·
verified ·
1 Parent(s): 149a666

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -395,6 +395,12 @@ def build_ui() -> gr.Blocks:
395
  analytics_enabled=False) as ui:
396
  session = gr.State(value=new_session)
397
 
 
 
 
 
 
 
398
  gr.HTML(MASTHEAD)
399
  verdict = gr.HTML(idle_verdict(START_LANG))
400
 
@@ -497,9 +503,14 @@ def build_ui() -> gr.Blocks:
497
  return ui
498
 
499
 
 
 
 
 
 
 
500
  if __name__ == "__main__":
501
- build_ui().launch(
502
- css=CSS,
503
  theme=gr.themes.Base(),
504
  # Spaces route traffic to the container, so it must bind all interfaces.
505
  # Locally, stay on loopback so the dev server is not exposed to the LAN.
 
395
  analytics_enabled=False) as ui:
396
  session = gr.State(value=new_session)
397
 
398
+ # Inject the stylesheet into the page rather than passing css= to
399
+ # launch(). On Spaces the platform imports this module and calls
400
+ # launch() itself, so any styling passed there is silently dropped -
401
+ # the app would deploy looking completely unstyled.
402
+ gr.HTML(f"<style>{CSS}</style>")
403
+
404
  gr.HTML(MASTHEAD)
405
  verdict = gr.HTML(idle_verdict(START_LANG))
406
 
 
503
  return ui
504
 
505
 
506
+ # Module-level so Hugging Face Spaces can find it. The Gradio SDK imports this
507
+ # file and serves the top-level Blocks object - it never runs the __main__
508
+ # block, so an app that only builds its UI in there deploys as a blank Space.
509
+ demo = build_ui()
510
+
511
+
512
  if __name__ == "__main__":
513
+ demo.launch(
 
514
  theme=gr.themes.Base(),
515
  # Spaces route traffic to the container, so it must bind all interfaces.
516
  # Locally, stay on loopback so the dev server is not exposed to the LAN.