Lvvbaaal commited on
Commit
6142ebc
·
verified ·
1 Parent(s): 5c7a292

Deploy SaulGPT backend with full ChromaDB, Supabase, and Gradio API server

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -61,26 +61,32 @@ demo = gr.Interface(
61
  description="Backend engine for SaulGPT. Integrated with Supabase PostgreSQL, ChromaDB, and ZeroGPU acceleration. Multi-device web client available at https://legalgpt-india.web.app"
62
  )
63
 
64
- # 3. Attach all FastAPI backend routes to Gradio's internal FastAPI app
65
- demo.app.include_router(fastapi_app.router)
66
-
67
- # 4. Attach CORS middleware so the Firebase frontend can communicate freely
68
- demo.app.add_middleware(
69
- CORSMiddleware,
70
- allow_origins=["*"],
71
- allow_credentials=True,
72
- allow_methods=["*"],
73
- allow_headers=["*"],
74
- )
75
-
76
- # 5. Attach BYOK middleware
77
- demo.app.middleware("http")(byok_middleware)
78
-
79
- # 6. Initialize database during server launch
80
  try:
81
  init_db()
82
  except Exception as _e:
83
  print(f"init_db check: {_e}")
84
 
85
  if __name__ == "__main__":
86
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  description="Backend engine for SaulGPT. Integrated with Supabase PostgreSQL, ChromaDB, and ZeroGPU acceleration. Multi-device web client available at https://legalgpt-india.web.app"
62
  )
63
 
64
+ # Initialize Supabase database
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  try:
66
  init_db()
67
  except Exception as _e:
68
  print(f"init_db check: {_e}")
69
 
70
  if __name__ == "__main__":
71
+ # Launch Gradio server in non-blocking mode to attach FastAPI routes
72
+ server_app, local_url, share_url = demo.launch(prevent_thread_lock=True)
73
+
74
+ # Mount all FastAPI routes onto the live Gradio server
75
+ server_app.include_router(fastapi_app.router)
76
+
77
+ # Add CORS middleware for client web apps
78
+ server_app.add_middleware(
79
+ CORSMiddleware,
80
+ allow_origins=["*"],
81
+ allow_credentials=True,
82
+ allow_methods=["*"],
83
+ allow_headers=["*"],
84
+ )
85
+
86
+ # Add BYOK header middleware
87
+ server_app.middleware("http")(byok_middleware)
88
+
89
+ print(f"SaulGPT API & Gradio UI live on {local_url} with full routes attached.")
90
+
91
+ # Block main thread to keep server alive
92
+ demo.block_thread()