Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,18 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from ultralytics import YOLO
|
3 |
import cv2
|
4 |
import numpy as np
|
5 |
from PIL import Image
|
6 |
import json
|
7 |
-
from fastapi import FastAPI
|
8 |
|
9 |
# Load your custom YOLO model
|
10 |
-
model = YOLO("
|
11 |
|
12 |
def detect_keypoints(image):
|
13 |
-
|
|
|
|
|
14 |
try:
|
15 |
# Convert PIL Image to numpy array
|
16 |
if isinstance(image, Image.Image):
|
@@ -59,26 +61,16 @@ def detect_keypoints(image):
|
|
59 |
except Exception as e:
|
60 |
return {"success": False, "error": str(e)}
|
61 |
|
62 |
-
# Create
|
63 |
-
app = FastAPI()
|
64 |
-
|
65 |
-
@app.post("/api/detect")
|
66 |
-
async def api_detect_keypoints(file: bytes):
|
67 |
-
try:
|
68 |
-
# Convert bytes to PIL Image
|
69 |
-
image = Image.open(io.BytesIO(file))
|
70 |
-
result = detect_keypoints(image)
|
71 |
-
return result
|
72 |
-
except Exception as e:
|
73 |
-
return {"success": False, "error": str(e)}
|
74 |
-
|
75 |
-
# Create Gradio interface
|
76 |
iface = gr.Interface(
|
77 |
fn=detect_keypoints,
|
78 |
inputs=gr.Image(type="pil"),
|
79 |
outputs=gr.JSON(),
|
80 |
-
title="YOLO Keypoint Detection"
|
|
|
|
|
81 |
)
|
82 |
|
83 |
-
#
|
84 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import io
|
3 |
from ultralytics import YOLO
|
4 |
import cv2
|
5 |
import numpy as np
|
6 |
from PIL import Image
|
7 |
import json
|
|
|
8 |
|
9 |
# Load your custom YOLO model
|
10 |
+
model = YOLO("0829_kh_11_fenh_ft_544.pt")
|
11 |
|
12 |
def detect_keypoints(image):
|
13 |
+
"""
|
14 |
+
Run YOLO inference and return keypoints data
|
15 |
+
"""
|
16 |
try:
|
17 |
# Convert PIL Image to numpy array
|
18 |
if isinstance(image, Image.Image):
|
|
|
61 |
except Exception as e:
|
62 |
return {"success": False, "error": str(e)}
|
63 |
|
64 |
+
# Create Gradio interface with API access enabled
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
iface = gr.Interface(
|
66 |
fn=detect_keypoints,
|
67 |
inputs=gr.Image(type="pil"),
|
68 |
outputs=gr.JSON(),
|
69 |
+
title="YOLO Keypoint Detection",
|
70 |
+
description="Upload an image to detect keypoints using custom YOLO model",
|
71 |
+
api_name="predict" # This enables API access at /api/predict
|
72 |
)
|
73 |
|
74 |
+
# Launch with API enabled
|
75 |
+
if __name__ == "__main__":
|
76 |
+
iface.launch(share=False)
|