Spaces:
Running
Running
wjm55
commited on
Commit
·
fae55a0
1
Parent(s):
f2693c5
Refactor model loading in app.py to create a models directory and update local model path. Modify test.py to change default model ID and use a variable for the local app URL.
Browse files
app.py
CHANGED
@@ -20,11 +20,13 @@ def init_model(model_id: str):
|
|
20 |
"YOLOv11-XLarge": "medieval-yolov11x.pt"
|
21 |
}
|
22 |
if model_id in MODEL_OPTIONS:
|
|
|
23 |
model_path = hf_hub_download(
|
24 |
repo_id="biglam/medieval-manuscript-yolov11",
|
25 |
filename=MODEL_OPTIONS[model_id]
|
26 |
)
|
27 |
-
|
|
|
28 |
else:
|
29 |
raise ValueError(f"Model {model_id} not found")
|
30 |
|
|
|
20 |
"YOLOv11-XLarge": "medieval-yolov11x.pt"
|
21 |
}
|
22 |
if model_id in MODEL_OPTIONS:
|
23 |
+
os.makedirs("models", exist_ok=True)
|
24 |
model_path = hf_hub_download(
|
25 |
repo_id="biglam/medieval-manuscript-yolov11",
|
26 |
filename=MODEL_OPTIONS[model_id]
|
27 |
)
|
28 |
+
local_path = os.path.join("models", model_path)
|
29 |
+
return YOLO(local_path)
|
30 |
else:
|
31 |
raise ValueError(f"Model {model_id} not found")
|
32 |
|
test.py
CHANGED
@@ -3,6 +3,8 @@ import requests
|
|
3 |
# Path to your image
|
4 |
image_path = "/Users/wjm55/yale/weaviate-test/yolov11_output/valid/images/Paris_BnF_Velins_611_00003.jpg"
|
5 |
|
|
|
|
|
6 |
# Open the image file
|
7 |
with open(image_path, 'rb') as f:
|
8 |
# Create the files parameter for the POST request
|
@@ -10,13 +12,13 @@ with open(image_path, 'rb') as f:
|
|
10 |
|
11 |
# Optional parameters (using defaults from the API)
|
12 |
params = {
|
13 |
-
'model_id': 'YOLOv11-
|
14 |
'conf': 0.25, # confidence threshold
|
15 |
'iou': 0.7 # IoU threshold
|
16 |
}
|
17 |
|
18 |
# Send POST request to the endpoint
|
19 |
-
response = requests.post('
|
20 |
files=files,
|
21 |
params=params)
|
22 |
|
|
|
3 |
# Path to your image
|
4 |
image_path = "/Users/wjm55/yale/weaviate-test/yolov11_output/valid/images/Paris_BnF_Velins_611_00003.jpg"
|
5 |
|
6 |
+
hf_app = "https://wjbmattingly-medieval-yolo-api.hf.space"
|
7 |
+
local_app = "http://localhost"
|
8 |
# Open the image file
|
9 |
with open(image_path, 'rb') as f:
|
10 |
# Create the files parameter for the POST request
|
|
|
12 |
|
13 |
# Optional parameters (using defaults from the API)
|
14 |
params = {
|
15 |
+
'model_id': 'YOLOv11-Nano', # default model
|
16 |
'conf': 0.25, # confidence threshold
|
17 |
'iou': 0.7 # IoU threshold
|
18 |
}
|
19 |
|
20 |
# Send POST request to the endpoint
|
21 |
+
response = requests.post(local_app + ':7860/predict',
|
22 |
files=files,
|
23 |
params=params)
|
24 |
|