Update app.py
Browse files
app.py
CHANGED
@@ -533,7 +533,23 @@ def handle_message(data):
|
|
533 |
emit('json_response', response, room=session_id)
|
534 |
session_store.pop(session_id, None)
|
535 |
|
536 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
@socketio.on('example')
|
538 |
def handle_message(data):
|
539 |
img_url = data['img_url']
|
|
|
533 |
emit('json_response', response, room=session_id)
|
534 |
session_store.pop(session_id, None)
|
535 |
|
536 |
+
import base64
|
537 |
+
import numpy as np
|
538 |
+
from io import BytesIO
|
539 |
+
from PIL import Image
|
540 |
+
|
541 |
+
def base64_to_numpy(base64_string):
|
542 |
+
# Decode the base64 string
|
543 |
+
image_data = base64.b64decode(base64_string)
|
544 |
+
|
545 |
+
# Convert the byte data to a PIL image
|
546 |
+
image = Image.open(BytesIO(image_data))
|
547 |
+
|
548 |
+
# Convert the PIL image to a NumPy array
|
549 |
+
image_np = np.array(image)
|
550 |
+
|
551 |
+
return image_np
|
552 |
+
|
553 |
@socketio.on('example')
|
554 |
def handle_message(data):
|
555 |
img_url = data['img_url']
|