-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_inference.py
More file actions
43 lines (35 loc) · 1.25 KB
/
Copy pathtest_inference.py
File metadata and controls
43 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
import os
import shutil
def test_app_predictions():
url = 'http://127.0.0.1:5000/analyze'
# Generate a dummy image
dummy_img = 'test_pred.jpg'
import cv2
import numpy as np
img = np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)
cv2.imwrite(dummy_img, img)
allowed = {'Acne', 'Psoriasis', 'Vitiligo', 'Eczema (Atopic Dermatitis)', 'Warts'}
print("Testing predictions...")
try:
with open(dummy_img, 'rb') as f:
files = {'file': f}
response = requests.post(url, files=files)
if response.status_code == 200:
data = response.json()
print(f"Full Response: {data}")
pred = data.get('prediction')
print(f"Prediction: {pred}")
if pred in allowed:
print("PASS: Prediction is in allowed list.")
else:
print(f"FAIL: Prediction '{pred}' is NOT in allowed list.")
else:
print(f"FAIL: Status code {response.status_code}")
except Exception as e:
print(f"Error: {e}")
finally:
if os.path.exists(dummy_img):
os.remove(dummy_img)
if __name__ == "__main__":
test_app_predictions()