vasanthfeb13 commited on
Commit
7bd04f5
·
1 Parent(s): 581bd1c

Fix: Start background services at global scope for Gradio SDK

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -92,7 +92,10 @@ def start_orchestrator_api():
92
  uvicorn.run(orchestrator_app, host="127.0.0.1", port=8888)
93
 
94
  # Start background services
95
- if __name__ == "__main__":
 
 
 
96
  # 1. Start the Orchestrator API in a thread
97
  api_thread = threading.Thread(target=start_orchestrator_api, daemon=True)
98
  api_thread.start()
@@ -103,8 +106,10 @@ if __name__ == "__main__":
103
 
104
  # 3. Give services a moment to spin up
105
  time.sleep(3)
106
-
107
- # 4. Launch the UI
108
- print("💻 Launching NACC UI...")
109
- demo = create_ui()
 
 
110
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
92
  uvicorn.run(orchestrator_app, host="127.0.0.1", port=8888)
93
 
94
  # Start background services
95
+ # NOTE: For 'sdk: gradio', this must run at import time, not just in __main__
96
+ if not os.environ.get("NACC_SERVICES_STARTED"):
97
+ os.environ["NACC_SERVICES_STARTED"] = "1"
98
+
99
  # 1. Start the Orchestrator API in a thread
100
  api_thread = threading.Thread(target=start_orchestrator_api, daemon=True)
101
  api_thread.start()
 
106
 
107
  # 3. Give services a moment to spin up
108
  time.sleep(3)
109
+
110
+ # 4. Create the UI (Gradio will launch this)
111
+ print("💻 Launching NACC UI...")
112
+ demo = create_ui()
113
+
114
+ if __name__ == "__main__":
115
  demo.launch(server_name="0.0.0.0", server_port=7860)