Spaces:
Runtime error
Runtime error
parth parekh
commited on
Commit
·
e61ad95
1
Parent(s):
5f1e9dd
trying to download the model directly
Browse files- Dockerfile +0 -2
- app.py +18 -1
- requirements.txt +2 -1
Dockerfile
CHANGED
@@ -16,7 +16,5 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
16 |
|
17 |
COPY . .
|
18 |
|
19 |
-
# Download the 640m model
|
20 |
-
RUN wget https://github.com/notAI-tech/NudeNet/releases/download/v3.4-weights/640m.pt -O /app/640m.pt
|
21 |
|
22 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "4"]
|
|
|
16 |
|
17 |
COPY . .
|
18 |
|
|
|
|
|
19 |
|
20 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "4"]
|
app.py
CHANGED
@@ -10,6 +10,7 @@ from nudenet import NudeDetector
|
|
10 |
import cv2
|
11 |
from moviepy.editor import VideoFileClip
|
12 |
from typing import Optional
|
|
|
13 |
|
14 |
app = FastAPI(
|
15 |
title="Nudenet API",
|
@@ -18,10 +19,26 @@ app = FastAPI(
|
|
18 |
docs_url="/",
|
19 |
redoc_url="/redoc"
|
20 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# Initialize NudeDetector with both models
|
23 |
detector_320n = NudeDetector()
|
24 |
-
detector_640m = NudeDetector(model_path=
|
25 |
|
26 |
class Base64Image(BaseModel):
|
27 |
image: str
|
|
|
10 |
import cv2
|
11 |
from moviepy.editor import VideoFileClip
|
12 |
from typing import Optional
|
13 |
+
import requests
|
14 |
|
15 |
app = FastAPI(
|
16 |
title="Nudenet API",
|
|
|
19 |
docs_url="/",
|
20 |
redoc_url="/redoc"
|
21 |
)
|
22 |
+
def download_model(model_name):
|
23 |
+
url = f"https://github.com/notAI-tech/NudeNet/releases/download/v3.4-weights/{model_name}"
|
24 |
+
local_path = f"/app/{model_name}"
|
25 |
+
if not os.path.exists(local_path):
|
26 |
+
print(f"Downloading {model_name}...")
|
27 |
+
response = requests.get(url)
|
28 |
+
if response.status_code == 200:
|
29 |
+
with open(local_path, "wb") as f:
|
30 |
+
f.write(response.content)
|
31 |
+
print(f"{model_name} downloaded successfully.")
|
32 |
+
else:
|
33 |
+
print(f"Failed to download {model_name}. Using default model.")
|
34 |
+
return local_path
|
35 |
+
|
36 |
+
# Download only the 640m model
|
37 |
+
model_640m_path = download_model("640m.pt")
|
38 |
|
39 |
# Initialize NudeDetector with both models
|
40 |
detector_320n = NudeDetector()
|
41 |
+
detector_640m = NudeDetector(model_path=model_640m_path, inference_resolution=640)
|
42 |
|
43 |
class Base64Image(BaseModel):
|
44 |
image: str
|
requirements.txt
CHANGED
@@ -4,4 +4,5 @@ pillow==8.3.2
|
|
4 |
nudenet==3.4.2
|
5 |
opencv-python-headless==4.5.5.64
|
6 |
moviepy==1.0.3
|
7 |
-
python-multipart==0.0.5
|
|
|
|
4 |
nudenet==3.4.2
|
5 |
opencv-python-headless==4.5.5.64
|
6 |
moviepy==1.0.3
|
7 |
+
python-multipart==0.0.5
|
8 |
+
requests==2.26.0
|