sakshee05 commited on
Commit
378a602
·
verified ·
1 Parent(s): b54e321

Set cache directory for LangSAM

Browse files
Files changed (1) hide show
  1. main.py +10 -4
main.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  from fastapi import FastAPI, File, UploadFile, Form
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import Response
@@ -10,15 +13,18 @@ import supervision as sv
10
 
11
  app = FastAPI()
12
 
13
- # Enable CORS for all origins (Adjust as needed)
14
  app.add_middleware(
15
  CORSMiddleware,
16
- allow_origins=["*"], # Allow requests from any origin (Change this for security)
17
  allow_credentials=True,
18
- allow_methods=["*"], # Allow all HTTP methods
19
- allow_headers=["*"], # Allow all headers
20
  )
21
 
 
 
 
22
  # Load the segmentation model
23
  model = LangSAM()
24
 
 
1
+ import os
2
+ os.environ["TORCH_HOME"] = "/app/cache" # Set a writable directory
3
+
4
  from fastapi import FastAPI, File, UploadFile, Form
5
  from fastapi.middleware.cors import CORSMiddleware
6
  from fastapi.responses import Response
 
13
 
14
  app = FastAPI()
15
 
16
+ # Enable CORS for all origins
17
  app.add_middleware(
18
  CORSMiddleware,
19
+ allow_origins=["*"],
20
  allow_credentials=True,
21
+ allow_methods=["*"],
22
+ allow_headers=["*"],
23
  )
24
 
25
+ # Create a cache directory in the app space
26
+ os.makedirs("/app/cache", exist_ok=True)
27
+
28
  # Load the segmentation model
29
  model = LangSAM()
30