amitkumar299 commited on
Commit
c031299
·
verified ·
1 Parent(s): d05562c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -8,8 +8,17 @@ app = Flask(__name__)
8
  model = YOLO("yolov8n.pt")
9
 
10
  def readb64(base64_string):
11
- nparr = np.frombuffer(base64.b64decode(base64_string.split(',')[1]), np.uint8)
12
- return cv2.imdecode(nparr, cv2.IMREAD_COLOR)
 
 
 
 
 
 
 
 
 
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():