Update handler.py
Browse files- handler.py +22 -0
handler.py
CHANGED
|
@@ -24,6 +24,28 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
| 24 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 25 |
dtype = torch.float16 if str(device).__contains__("cuda") else torch.float32
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Load face encoder
|
| 28 |
face_analysis = FaceAnalysis(name="antelopev2", root="./models", providers=["CPUExecutionProvider"])
|
| 29 |
face_analysis.prepare(ctx_id=0, det_size=(640, 640))
|
|
|
|
| 24 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 25 |
dtype = torch.float16 if str(device).__contains__("cuda") else torch.float32
|
| 26 |
|
| 27 |
+
# Ensure the antelopev2 model is available locally
|
| 28 |
+
model_dir = "./models/antelopev2"
|
| 29 |
+
model_repo_url = "https://huggingface.co/Jacobmadwed/ocmhelp/tree/main/models/antelopev2/"
|
| 30 |
+
|
| 31 |
+
import os
|
| 32 |
+
import requests
|
| 33 |
+
|
| 34 |
+
def download_model_files(model_dir, model_repo_url):
|
| 35 |
+
os.makedirs(model_dir, exist_ok=True)
|
| 36 |
+
files = ["det_10g.onnx", "w600k_r50.onnx", "model.onnx"]
|
| 37 |
+
for file in files:
|
| 38 |
+
url = model_repo_url + file
|
| 39 |
+
local_path = os.path.join(model_dir, file)
|
| 40 |
+
if not os.path.exists(local_path):
|
| 41 |
+
print(f"Downloading {file}...")
|
| 42 |
+
response = requests.get(url)
|
| 43 |
+
with open(local_path, "wb") as f:
|
| 44 |
+
f.write(response.content)
|
| 45 |
+
print(f"Downloaded {file} to {local_path}")
|
| 46 |
+
|
| 47 |
+
download_model_files(model_dir, model_repo_url)
|
| 48 |
+
|
| 49 |
# Load face encoder
|
| 50 |
face_analysis = FaceAnalysis(name="antelopev2", root="./models", providers=["CPUExecutionProvider"])
|
| 51 |
face_analysis.prepare(ctx_id=0, det_size=(640, 640))
|