shubham5524 commited on
Commit
8c5f69e
·
verified ·
1 Parent(s): 60c543d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -9
main.py CHANGED
@@ -20,18 +20,20 @@ from io import BytesIO
20
  import logging
21
  logging.getLogger("uvicorn").setLevel(logging.WARNING)
22
 
23
- import os
24
-
25
- # Set a custom path for Matplotlib to use
26
- os.environ["MPLCONFIGDIR"] = "/app/.cache/matplotlib"
27
 
28
- # Set a custom path for TorchXRayVision to use for model weights
29
- os.environ["TORCHXrayVISION_CACHE"] = "/app/.cache/torchxrayvision"
 
 
30
 
31
- # Create these directories if they do not exist
32
- os.makedirs("/app/.cache/matplotlib", exist_ok=True)
33
- os.makedirs("/app/.cache/torchxrayvision", exist_ok=True)
34
 
 
 
 
35
 
36
 
37
  app = FastAPI()
 
20
  import logging
21
  logging.getLogger("uvicorn").setLevel(logging.WARNING)
22
 
23
+ import tempfile
 
 
 
24
 
25
+ # Instead of hardcoding paths to /app/.cache
26
+ temp_dir = tempfile.gettempdir()
27
+ matplotlib_cache = os.path.join(temp_dir, "matplotlib")
28
+ torchxrayvision_cache = os.path.join(temp_dir, "torchxrayvision")
29
 
30
+ # Set environment variables to use these paths
31
+ os.environ["MPLCONFIGDIR"] = matplotlib_cache
32
+ os.environ["TORCHXrayVISION_CACHE"] = torchxrayvision_cache
33
 
34
+ # Create directories
35
+ os.makedirs(matplotlib_cache, exist_ok=True)
36
+ os.makedirs(torchxrayvision_cache, exist_ok=True)
37
 
38
 
39
  app = FastAPI()