Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,16 +11,17 @@ from flask import Flask, request, jsonify
|
|
11 |
from transformers import pipeline
|
12 |
from PIL import Image
|
13 |
|
14 |
-
# β
Set Hugging Face cache
|
15 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface_cache"
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# β
Initialize FastAPI and Flask
|
18 |
app_fastapi = FastAPI()
|
19 |
app_flask = Flask(__name__)
|
20 |
|
21 |
-
# β
Ensure the cache directory exists (use /tmp for permission safety)
|
22 |
-
os.makedirs("/tmp/huggingface_cache", exist_ok=True)
|
23 |
-
|
24 |
# β
Load NSFW Image Classification Model
|
25 |
pipe = pipeline("image-classification", model="LukeJacob2023/nsfw-image-detector")
|
26 |
|
|
|
11 |
from transformers import pipeline
|
12 |
from PIL import Image
|
13 |
|
14 |
+
# β
Set Hugging Face cache to a writable directory
|
15 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface_cache"
|
16 |
+
os.environ["HF_HOME"] = "/tmp/huggingface_cache"
|
17 |
+
|
18 |
+
# β
Ensure the cache directory exists
|
19 |
+
os.makedirs("/tmp/huggingface_cache", exist_ok=True)
|
20 |
|
21 |
# β
Initialize FastAPI and Flask
|
22 |
app_fastapi = FastAPI()
|
23 |
app_flask = Flask(__name__)
|
24 |
|
|
|
|
|
|
|
25 |
# β
Load NSFW Image Classification Model
|
26 |
pipe = pipeline("image-classification", model="LukeJacob2023/nsfw-image-detector")
|
27 |
|