Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ assets = joblib.load("deployment_assets.joblib")
|
|
| 12 |
transform = assets['transform']
|
| 13 |
class_names = assets['class_names']
|
| 14 |
|
|
|
|
| 15 |
items = ['Bisconni Chocolate Chip Cookies 46.8gm', 'Coca Cola Can 250ml', 'Colgate Maximum Cavity Protection 75gm',
|
| 16 |
'Fanta 500ml', 'Fresher Guava Nectar 500ml', 'Fruita Vitals Red Grapes 200ml', 'Islamabad Tea 238gm',
|
| 17 |
'Kolson Slanty Jalapeno 18gm', 'Kurkure Chutney Chaska 62gm', 'LU Candi Biscuit 60gm', 'LU Oreo Biscuit 19gm',
|
|
@@ -25,11 +26,13 @@ prices = [55.20, 31.75, 90.00, 63.50, 50.00, 35.00, 150.00, 15.00, 25.00, 30.00,
|
|
| 25 |
|
| 26 |
pricelist = dict(zip(items, prices))
|
| 27 |
|
|
|
|
| 28 |
def add_image(new_img, image_list):
|
| 29 |
if new_img:
|
| 30 |
image_list.append(new_img)
|
| 31 |
return image_list, image_list
|
| 32 |
|
|
|
|
| 33 |
def classify_and_track(images, budget):
|
| 34 |
results = []
|
| 35 |
total_cost = 0
|
|
@@ -74,7 +77,7 @@ def classify_and_track(images, budget):
|
|
| 74 |
receipt_text = "\n".join(receipt_lines)
|
| 75 |
return results, receipt_text
|
| 76 |
|
| 77 |
-
# Custom Theme
|
| 78 |
custom_theme = gr.themes.Base(
|
| 79 |
primary_hue="rose",
|
| 80 |
secondary_hue="amber",
|
|
@@ -84,12 +87,12 @@ custom_theme = gr.themes.Base(
|
|
| 84 |
body_background_fill="#ffe5e5"
|
| 85 |
)
|
| 86 |
|
| 87 |
-
# Gradio Interface
|
| 88 |
with gr.Blocks(theme=custom_theme) as demo:
|
| 89 |
gr.Markdown(
|
| 90 |
"""
|
| 91 |
-
#
|
| 92 |
-
Upload an image, and ScanCart finds the items, checks the prices, builds your cart, and lets you know if it fits your budget.
|
| 93 |
Like having a shopping assistant with scanner vision. ๐๐ธ
|
| 94 |
"""
|
| 95 |
)
|
|
@@ -108,11 +111,15 @@ with gr.Blocks(theme=custom_theme) as demo:
|
|
| 108 |
image_list_state = gr.State([])
|
| 109 |
|
| 110 |
add_btn.click(
|
| 111 |
-
add_image,
|
| 112 |
inputs=[image_input, image_list_state],
|
| 113 |
outputs=[image_list_state, gallery_output]
|
| 114 |
)
|
| 115 |
|
| 116 |
classify_btn.click(
|
| 117 |
-
classify_and_track,
|
| 118 |
-
inputs=[image_list_state]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
transform = assets['transform']
|
| 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',
|
|
|
|
| 26 |
|
| 27 |
pricelist = dict(zip(items, prices))
|
| 28 |
|
| 29 |
+
# Add image to 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 and create receipt
|
| 36 |
def classify_and_track(images, budget):
|
| 37 |
results = []
|
| 38 |
total_cost = 0
|
|
|
|
| 77 |
receipt_text = "\n".join(receipt_lines)
|
| 78 |
return results, receipt_text
|
| 79 |
|
| 80 |
+
# ๐จ Custom Theme
|
| 81 |
custom_theme = gr.themes.Base(
|
| 82 |
primary_hue="rose",
|
| 83 |
secondary_hue="amber",
|
|
|
|
| 87 |
body_background_fill="#ffe5e5"
|
| 88 |
)
|
| 89 |
|
| 90 |
+
# ๐๏ธ Gradio Interface
|
| 91 |
with gr.Blocks(theme=custom_theme) as demo:
|
| 92 |
gr.Markdown(
|
| 93 |
"""
|
| 94 |
+
# **ScanCart ๐งพ**
|
| 95 |
+
* Upload an image, and ScanCart finds the items, checks the prices, builds your cart, and lets you know if it fits your budget.
|
| 96 |
Like having a shopping assistant with scanner vision. ๐๐ธ
|
| 97 |
"""
|
| 98 |
)
|
|
|
|
| 111 |
image_list_state = gr.State([])
|
| 112 |
|
| 113 |
add_btn.click(
|
| 114 |
+
fn=add_image,
|
| 115 |
inputs=[image_input, image_list_state],
|
| 116 |
outputs=[image_list_state, gallery_output]
|
| 117 |
)
|
| 118 |
|
| 119 |
classify_btn.click(
|
| 120 |
+
fn=classify_and_track,
|
| 121 |
+
inputs=[image_list_state, budget_input],
|
| 122 |
+
outputs=[gallery_output, receipt_output]
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
demo.launch()
|