Update app.py
Browse files
app.py
CHANGED
|
@@ -13,41 +13,27 @@ transform = assets['transform']
|
|
| 13 |
class_names = assets['class_names']
|
| 14 |
|
| 15 |
# Item names and prices
|
| 16 |
-
items = [
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
'Lays Masala 34gm', 'Lays Wavy Mexican Chili 34gm',
|
| 24 |
-
'Lifebuoy Total Protect Soap 96gm', 'Lipton Yellow Label Tea 95gm',
|
| 25 |
-
'Meezan Ultra Rich Tea 190gm', 'Peek Freans Sooper Biscuit 13.2gm',
|
| 26 |
-
'Safeguard Bar Soap Pure White 175gm', 'Shezan Apple 250ml',
|
| 27 |
-
'Sunsilk Shampoo Soft - Smooth 160ml', 'Super Crisp BBQ 30gm',
|
| 28 |
-
'Supreme Tea 95gm', 'Tapal Danedar 95gm',
|
| 29 |
-
'Vaseline Healthy White Lotion 100ml'
|
| 30 |
-
]
|
| 31 |
-
|
| 32 |
-
prices = [
|
| 33 |
-
55.20, 31.75, 90.00, 63.50, 50.00, 35.00, 150.00, 15.00, 25.00,
|
| 34 |
-
30.00, 10.00, 30.00, 20.00, 20.00, 44.50, 100.00, 200.00, 10.00,
|
| 35 |
-
70.00, 25.00, 120.00, 15.00, 100.00, 100.00, 120.00
|
| 36 |
-
]
|
| 37 |
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
image_list = []
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
def add_image(new_img):
|
| 45 |
if new_img:
|
| 46 |
image_list.append(new_img)
|
| 47 |
return image_list, image_list
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
def classify_and_track(budget):
|
| 51 |
results = []
|
| 52 |
total_cost = 0
|
| 53 |
receipt_lines = []
|
|
@@ -58,7 +44,7 @@ def classify_and_track(budget):
|
|
| 58 |
receipt_lines.append(" ITEM PRICE")
|
| 59 |
receipt_lines.append(" ==============================")
|
| 60 |
|
| 61 |
-
for img in
|
| 62 |
if isinstance(img, Image.Image):
|
| 63 |
input_tensor = transform(img).unsqueeze(0)
|
| 64 |
with torch.no_grad():
|
|
@@ -105,9 +91,12 @@ custom_theme = gr.themes.Base(
|
|
| 105 |
with gr.Blocks(theme=custom_theme) as iface:
|
| 106 |
gr.Markdown(
|
| 107 |
"""
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
| 111 |
"""
|
| 112 |
)
|
| 113 |
|
|
@@ -122,16 +111,17 @@ with gr.Blocks(theme=custom_theme) as iface:
|
|
| 122 |
gallery_output = gr.Gallery(label="Cart Preview", columns=3, height="auto", object_fit="contain")
|
| 123 |
receipt_output = gr.Textbox(label="Receipt", lines=20, interactive=False, show_copy_button=True)
|
| 124 |
|
| 125 |
-
|
|
|
|
| 126 |
add_btn.click(
|
| 127 |
fn=add_image,
|
| 128 |
-
inputs=[image_input],
|
| 129 |
-
outputs=[
|
| 130 |
)
|
| 131 |
|
| 132 |
classify_btn.click(
|
| 133 |
fn=classify_and_track,
|
| 134 |
-
inputs=[budget_input],
|
| 135 |
outputs=[gallery_output, receipt_output]
|
| 136 |
)
|
| 137 |
|
|
|
|
| 13 |
class_names = assets['class_names']
|
| 14 |
|
| 15 |
# Item names and prices
|
| 16 |
+
items = ['Bisconni Chocolate Chip Cookies 46.8gm', 'Coca Cola Can 250ml', 'Colgate Maximum Cavity Protection 75gm',
|
| 17 |
+
'Fanta 500ml', 'Fresher Guava Nectar 500ml', 'Fruita Vitals Red Grapes 200ml', 'Islamabad Tea 238gm',
|
| 18 |
+
'Kolson Slanty Jalapeno 18gm', 'Kurkure Chutney Chaska 62gm', 'LU Candi Biscuit 60gm', 'LU Oreo Biscuit 19gm',
|
| 19 |
+
'LU Prince Biscuit 55.2gm', 'Lays Masala 34gm', 'Lays Wavy Mexican Chili 34gm', 'Lifebuoy Total Protect Soap 96gm',
|
| 20 |
+
'Lipton Yellow Label Tea 95gm', 'Meezan Ultra Rich Tea 190gm', 'Peek Freans Sooper Biscuit 13.2gm',
|
| 21 |
+
'Safeguard Bar Soap Pure White 175gm', 'Shezan Apple 250ml', 'Sunsilk Shampoo Soft - Smooth 160ml',
|
| 22 |
+
'Super Crisp BBQ 30gm', 'Supreme Tea 95gm', 'Tapal Danedar 95gm', 'Vaseline Healthy White Lotion 100ml']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
prices = [55.20, 31.75, 90.00, 63.50, 50.00, 35.00, 150.00, 15.00, 25.00, 30.00, 10.00, 30.00, 20.00, 20.00, 44.50, 100.00,
|
| 25 |
+
200.00, 10.00, 70.00, 25.00, 120.00, 15.00, 100.00, 100.00, 120.00]
|
| 26 |
|
| 27 |
+
pricelist = dict(zip(items, prices))
|
|
|
|
| 28 |
|
| 29 |
+
# Add uploaded image to state list
|
| 30 |
+
def add_image(new_img, image_list):
|
| 31 |
if new_img:
|
| 32 |
image_list.append(new_img)
|
| 33 |
return image_list, image_list
|
| 34 |
|
| 35 |
+
# Classify uploaded images and generate receipt
|
| 36 |
+
def classify_and_track(images, budget):
|
| 37 |
results = []
|
| 38 |
total_cost = 0
|
| 39 |
receipt_lines = []
|
|
|
|
| 44 |
receipt_lines.append(" ITEM PRICE")
|
| 45 |
receipt_lines.append(" ==============================")
|
| 46 |
|
| 47 |
+
for img in images:
|
| 48 |
if isinstance(img, Image.Image):
|
| 49 |
input_tensor = transform(img).unsqueeze(0)
|
| 50 |
with torch.no_grad():
|
|
|
|
| 91 |
with gr.Blocks(theme=custom_theme) as iface:
|
| 92 |
gr.Markdown(
|
| 93 |
"""
|
| 94 |
+
<div style="text-align:center">
|
| 95 |
+
<h1>🧾 ScanCart 🧾</h1>
|
| 96 |
+
<p>Upload images of your grocery items, and ScanCart will identify them,<br>
|
| 97 |
+
calculate the total cost, and check if it fits within your budget.<br><br>
|
| 98 |
+
It's like having a smart shopping assistant! 🛒📸</p>
|
| 99 |
+
</div>
|
| 100 |
"""
|
| 101 |
)
|
| 102 |
|
|
|
|
| 111 |
gallery_output = gr.Gallery(label="Cart Preview", columns=3, height="auto", object_fit="contain")
|
| 112 |
receipt_output = gr.Textbox(label="Receipt", lines=20, interactive=False, show_copy_button=True)
|
| 113 |
|
| 114 |
+
image_list_state = gr.State([])
|
| 115 |
+
|
| 116 |
add_btn.click(
|
| 117 |
fn=add_image,
|
| 118 |
+
inputs=[image_input, image_list_state],
|
| 119 |
+
outputs=[image_list_state, gallery_output]
|
| 120 |
)
|
| 121 |
|
| 122 |
classify_btn.click(
|
| 123 |
fn=classify_and_track,
|
| 124 |
+
inputs=[image_list_state, budget_input],
|
| 125 |
outputs=[gallery_output, receipt_output]
|
| 126 |
)
|
| 127 |
|