Spaces:
Runtime error
Runtime error
Commit
·
ee7ed58
1
Parent(s):
93d0dcd
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from transformers import pipeline
|
|
| 3 |
from PIL import Image, ImageDraw, ImageFont
|
| 4 |
import gradio as gr
|
| 5 |
|
|
|
|
| 6 |
# Draw bounding box definition
|
| 7 |
def draw_bounding_box(im, score, label, xmin, ymin, xmax, ymax, index, num_boxes):
|
| 8 |
""" Draw a bounding box. """
|
|
@@ -21,6 +22,8 @@ def object_classify(img):
|
|
| 21 |
object_detector = pipeline("object-detection", model = model, feature_extractor = feature_extractor)
|
| 22 |
bboxes = object_detector(img)
|
| 23 |
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Iteration elements
|
| 26 |
num_boxes = len(bboxes)
|
|
@@ -28,6 +31,13 @@ def object_classify(img):
|
|
| 28 |
|
| 29 |
# Draw bounding box for each result
|
| 30 |
for i in bboxes:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
box = i['box']
|
| 32 |
#Draw the bounding box
|
| 33 |
output_image = draw_bounding_box(img, i['score'],i['label'],
|
|
@@ -35,12 +45,13 @@ def object_classify(img):
|
|
| 35 |
box['xmax'], box['ymax'],
|
| 36 |
index, num_boxes)
|
| 37 |
index += 1
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
TITLE = 'Object Detection for Effective Self-Checkout in Grocery Shopping [Work In Progress]'
|
| 41 |
-
DESCRIPTION = 'A deep learning application to reimagine self-checkout stores.'
|
| 42 |
EXAMPLES = ['ex1.jpg']
|
| 43 |
interface=gr.Interface(object_classify,
|
| 44 |
-
gr.inputs.Image(type = 'pil'),gr.outputs.Image(),
|
| 45 |
examples = EXAMPLES,title = TITLE, description=DESCRIPTION, allow_flagging="never")
|
| 46 |
interface.launch()
|
|
|
|
| 3 |
from PIL import Image, ImageDraw, ImageFont
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
|
| 7 |
# Draw bounding box definition
|
| 8 |
def draw_bounding_box(im, score, label, xmin, ymin, xmax, ymax, index, num_boxes):
|
| 9 |
""" Draw a bounding box. """
|
|
|
|
| 22 |
object_detector = pipeline("object-detection", model = model, feature_extractor = feature_extractor)
|
| 23 |
bboxes = object_detector(img)
|
| 24 |
|
| 25 |
+
price_total = 0
|
| 26 |
+
total_items_in_cart = 0
|
| 27 |
|
| 28 |
# Iteration elements
|
| 29 |
num_boxes = len(bboxes)
|
|
|
|
| 31 |
|
| 32 |
# Draw bounding box for each result
|
| 33 |
for i in bboxes:
|
| 34 |
+
if i['label'] == 'apple':
|
| 35 |
+
price_total += 25 #pesos? dunno
|
| 36 |
+
elif i['label'] == 'bottle':
|
| 37 |
+
price_total += 15
|
| 38 |
+
elif i['label'] == 'broccoli':
|
| 39 |
+
price_total += 100
|
| 40 |
+
|
| 41 |
box = i['box']
|
| 42 |
#Draw the bounding box
|
| 43 |
output_image = draw_bounding_box(img, i['score'],i['label'],
|
|
|
|
| 45 |
box['xmax'], box['ymax'],
|
| 46 |
index, num_boxes)
|
| 47 |
index += 1
|
| 48 |
+
total_items_in_cart += 1
|
| 49 |
+
return output_image, str(price_total), str(total_items_in_cart)
|
| 50 |
|
| 51 |
TITLE = 'Object Detection for Effective Self-Checkout in Grocery Shopping [Work In Progress]'
|
| 52 |
+
DESCRIPTION = 'A deep learning application using DETR model to reimagine self-checkout stores.'
|
| 53 |
EXAMPLES = ['ex1.jpg']
|
| 54 |
interface=gr.Interface(object_classify,
|
| 55 |
+
gr.inputs.Image(type = 'pil'),outputs = [gr.outputs.Image(), gr.outputs.Textbox(label='Total Price: ')],
|
| 56 |
examples = EXAMPLES,title = TITLE, description=DESCRIPTION, allow_flagging="never")
|
| 57 |
interface.launch()
|