Spaces:
Sleeping
Sleeping
fahmiaziz98
commited on
Commit
·
40ea044
1
Parent(s):
540c05e
frist commit
Browse files- router/image_clf.py +4 -14
router/image_clf.py
CHANGED
@@ -14,16 +14,6 @@ router = APIRouter()
|
|
14 |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
15 |
MODEL_PATH = os.path.join(BASE_DIR, "ml-models", "vit-human-pose-classification/")
|
16 |
|
17 |
-
def download_image(url):
|
18 |
-
"""Download and open an image from a URL."""
|
19 |
-
try:
|
20 |
-
response = requests.get(url)
|
21 |
-
response.raise_for_status()
|
22 |
-
return Image.open(BytesIO(response.content)).convert("RGB")
|
23 |
-
except Exception as e:
|
24 |
-
raise HTTPException(status_code=400, detail=f"Failed to download image: {e}")
|
25 |
-
|
26 |
-
|
27 |
@router.post(
|
28 |
"/image_classification",
|
29 |
response_model=ImageOutput,
|
@@ -33,12 +23,12 @@ def download_image(url):
|
|
33 |
def image_classification(input: ImageInput)-> ImageOutput:
|
34 |
try:
|
35 |
pipe = load_model(MODEL_PATH, is_image_model=True)
|
36 |
-
|
37 |
-
|
38 |
-
logger.info(f"Image URLs: {
|
39 |
|
40 |
start = time.time()
|
41 |
-
output = pipe(
|
42 |
end = time.time()
|
43 |
|
44 |
prediction_time = int((end-start)*1000)
|
|
|
14 |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
15 |
MODEL_PATH = os.path.join(BASE_DIR, "ml-models", "vit-human-pose-classification/")
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
@router.post(
|
18 |
"/image_classification",
|
19 |
response_model=ImageOutput,
|
|
|
23 |
def image_classification(input: ImageInput)-> ImageOutput:
|
24 |
try:
|
25 |
pipe = load_model(MODEL_PATH, is_image_model=True)
|
26 |
+
image = input.url
|
27 |
+
|
28 |
+
logger.info(f"Image URLs: {image[-1]}")
|
29 |
|
30 |
start = time.time()
|
31 |
+
output = pipe(image[-1])
|
32 |
end = time.time()
|
33 |
|
34 |
prediction_time = int((end-start)*1000)
|