Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,8 +8,17 @@ app = Flask(__name__)
|
|
| 8 |
model = YOLO("yolov8n.pt")
|
| 9 |
|
| 10 |
def readb64(base64_string):
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
@app.route('/')
|
| 15 |
def index():
|
|
|
|
| 8 |
model = YOLO("yolov8n.pt")
|
| 9 |
|
| 10 |
def readb64(base64_string):
|
| 11 |
+
if ',' not in base64_string:
|
| 12 |
+
raise ValueError("Invalid base64 image string.")
|
| 13 |
+
header, encoded = base64_string.split(',', 1)
|
| 14 |
+
if not encoded:
|
| 15 |
+
raise ValueError("Empty base64 image data.")
|
| 16 |
+
nparr = np.frombuffer(base64.b64decode(encoded), np.uint8)
|
| 17 |
+
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
| 18 |
+
if img is None:
|
| 19 |
+
raise ValueError("Image decoding failed.")
|
| 20 |
+
return img
|
| 21 |
+
|
| 22 |
|
| 23 |
@app.route('/')
|
| 24 |
def index():
|