-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtasks.py
More file actions
31 lines (23 loc) · 828 Bytes
/
tasks.py
File metadata and controls
31 lines (23 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import msgpack
import os
from io import BytesIO
from PIL import Image
from celery import Celery
from classification import ClassificationTask
broker_address = os.environ.get('BROKER_ADDRESS', 'localhost')
app = Celery('wpi_demo', backend='rpc://', broker=f"pyamqp://guest@{broker_address}//")
app.conf.update(
accept_content=['msgpack'],
task_serializer='msgpack',
result_serializer='msgpack',
)
@app.task(name='document_classification', base=ClassificationTask)
def classify(task_data):
bytes = msgpack.unpackb(task_data)
classify.initialize()
image_data = BytesIO(bytes)
image_data.seek(0)
with Image.open(image_data) as decoded_image:
decoded_image = decoded_image.convert('RGB')
classification_result = classify.predict(decoded_image)
return classification_result