vaibhaviiii28 commited on
Commit
be6b2a3
Β·
verified Β·
1 Parent(s): b702e41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -8,16 +8,22 @@ import string
8
  import io
9
  import os
10
  import uvicorn
11
-
12
  # βœ… Set Hugging Face Cache Directory (Fixes Permission Error)
13
- CACHE_DIR = "/tmp/hf_cache"
14
- os.makedirs(CACHE_DIR, exist_ok=True)
 
 
 
 
 
 
 
15
 
16
  # βœ… Initialize FastAPI
17
  app = FastAPI()
18
-
19
  # βœ… Load NSFW Image Classification Model (with custom cache directory)
20
- pipe = pipeline("image-classification", model="LukeJacob2023/nsfw-image-detector", cache_dir="/tmp/hf_cache")
21
 
22
 
23
  # βœ… Load Toxic Text Classification Model
 
8
  import io
9
  import os
10
  import uvicorn
11
+ import os
12
  # βœ… Set Hugging Face Cache Directory (Fixes Permission Error)
13
+ import os
14
+
15
+ # βœ… Set Hugging Face Cache to a writable directory
16
+ os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_cache"
17
+ os.environ["HF_HOME"] = "/tmp/hf_cache"
18
+
19
+
20
+
21
+
22
 
23
  # βœ… Initialize FastAPI
24
  app = FastAPI()
25
+ pipe = pipeline("image-classification", model="LukeJacob2023/nsfw-image-detector")
26
  # βœ… Load NSFW Image Classification Model (with custom cache directory)
 
27
 
28
 
29
  # βœ… Load Toxic Text Classification Model