dschandra commited on
Commit
cc1f300
·
verified ·
1 Parent(s): b726d24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -37
app.py CHANGED
@@ -32,7 +32,7 @@ SALESFORCE_DOMAIN = os.getenv("SALESFORCE_DOMAIN", "login")
32
 
33
  # Validate that credentials are set
34
  if not all([SALESFORCE_USERNAME, SALESFORCE_PASSWORD, SALESFORCE_SECURITY_TOKEN]):
35
- logger.error("Salesforce credentials not set in environment variables. Please set SALESFORCE_USERNAME, SALESFORCE_PASSWORD, and SALESFORCE_SECURITY_TOKEN.")
36
  raise ValueError("Missing Salesforce credentials in environment variables.")
37
 
38
  logger.debug("Using Salesforce credentials - Username and Security Token loaded from environment variables.")
@@ -349,43 +349,12 @@ app.add_middleware(
349
  # Mount directory for temporary files (e.g., Gantt chart PNGs)
350
  app.mount("/static", StaticFiles(directory=tempfile.gettempdir()), name="static")
351
 
352
- # Mount Gradio's static assets to fix UI rendering issue
353
- gradio_base_path = gr.__path__[0]
354
- possible_static_paths = [
355
- os.path.join(gradio_base_path, "templates", "frontend", "dist"),
356
- os.path.join(gradio_base_path, "templates", "frontend", "build"),
357
- os.path.join(gradio_base_path, "static"),
358
- ]
359
-
360
- gradio_static_path = None
361
- for path in possible_static_paths:
362
- if os.path.exists(path) and os.path.exists(os.path.join(path, "_app")):
363
- gradio_static_path = path
364
- break
365
-
366
- if gradio_static_path:
367
- app.mount("/_app", StaticFiles(directory=gradio_static_path), name="gradio_static")
368
- logger.info(f"Mounted Gradio static assets at {gradio_static_path}")
369
- else:
370
- logger.warning(
371
- "Gradio static assets not found in any expected paths: " +
372
- ", ".join(possible_static_paths) +
373
- ". Falling back to Gradio's built-in server for UI rendering."
374
- )
375
- # Run Gradio directly if assets cannot be found
376
- if __name__ == "__main__":
377
- logger.info("Starting Gradio's built-in server...")
378
- demo.launch(server_name="0.0.0.0", server_port=7860)
379
- exit(0)
380
-
381
- # Health check endpoint to verify static asset availability
382
  @app.get("/health")
383
  async def health_check():
384
- if gradio_static_path and os.path.exists(gradio_static_path):
385
- return {"status": "healthy", "gradio_static": "available"}
386
- return {"status": "unhealthy", "gradio_static": "missing"}
387
 
388
- # FastAPI endpoint for Salesforce controller (defined before mounting Gradio)
389
  @app.post("/api/gradio_interface")
390
  async def api_gradio_interface(
391
  boq_file: UploadFile = File(...),
@@ -485,8 +454,8 @@ async def api_gradio_interface(
485
  shutil.rmtree(temp_dir)
486
  logger.debug(f"Cleaned up temporary directory: {temp_dir}")
487
 
488
- # Create Gradio interface with explicit base_path
489
- demo = gr.Blocks(theme="default", base_path="/")
490
  with demo:
491
  gr.Markdown("## AI Civil Work Planner")
492
  gr.Markdown("Generate a project timeline (Gantt chart) and risk tags based on BOQ data and site parameters.")
 
32
 
33
  # Validate that credentials are set
34
  if not all([SALESFORCE_USERNAME, SALESFORCE_PASSWORD, SALESFORCE_SECURITY_TOKEN]):
35
+ logger.error("Salesforce credentials not set in environment variables.")
36
  raise ValueError("Missing Salesforce credentials in environment variables.")
37
 
38
  logger.debug("Using Salesforce credentials - Username and Security Token loaded from environment variables.")
 
349
  # Mount directory for temporary files (e.g., Gantt chart PNGs)
350
  app.mount("/static", StaticFiles(directory=tempfile.gettempdir()), name="static")
351
 
352
+ # Health check endpoint to verify server status
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  @app.get("/health")
354
  async def health_check():
355
+ return {"status": "healthy"}
 
 
356
 
357
+ # FastAPI endpoint for Salesforce controller
358
  @app.post("/api/gradio_interface")
359
  async def api_gradio_interface(
360
  boq_file: UploadFile = File(...),
 
454
  shutil.rmtree(temp_dir)
455
  logger.debug(f"Cleaned up temporary directory: {temp_dir}")
456
 
457
+ # Create Gradio interface
458
+ demo = gr.Blocks(theme="default")
459
  with demo:
460
  gr.Markdown("## AI Civil Work Planner")
461
  gr.Markdown("Generate a project timeline (Gantt chart) and risk tags based on BOQ data and site parameters.")