Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -80,13 +80,13 @@ def suggest_items(query):
|
|
80 |
)
|
81 |
return "π€· Sorry, no smart suggestions found. Try asking: 'Gift items under 500' or 'Shampoo for dry hair'"
|
82 |
|
83 |
-
|
84 |
def reset_all():
|
85 |
return (
|
86 |
None, None, None, None, None, None, None,
|
87 |
-
gr.update(choices=[], visible=False), # quantity
|
88 |
-
"", # result textbox
|
89 |
-
{} # data_state
|
90 |
)
|
91 |
|
92 |
# ----- UI -----
|
@@ -110,28 +110,58 @@ with gr.Blocks(title="RetailGenie") as demo:
|
|
110 |
store_map = gr.Image(value=Image.open(DEFAULT_MAP), type="pil", label="πΊοΈ Store Map")
|
111 |
reset_btn = gr.Button("π Reset All")
|
112 |
|
113 |
-
# Dropdown chaining
|
114 |
-
country.change(
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
brand.change(
|
|
|
|
|
|
|
|
|
122 |
|
123 |
-
quantity.change(
|
|
|
|
|
|
|
|
|
124 |
|
125 |
-
product.change(
|
|
|
|
|
|
|
|
|
126 |
|
127 |
reset_btn.click(
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
)
|
136 |
|
137 |
with gr.TabItem("π Smart Suggestions"):
|
@@ -140,6 +170,10 @@ with gr.Blocks(title="RetailGenie") as demo:
|
|
140 |
suggest_btn = gr.Button("π‘ Get Suggestions")
|
141 |
suggestions_output = gr.Textbox(label="π Suggestions", lines=10)
|
142 |
|
143 |
-
suggest_btn.click(
|
|
|
|
|
|
|
|
|
144 |
|
145 |
demo.launch()
|
|
|
80 |
)
|
81 |
return "π€· Sorry, no smart suggestions found. Try asking: 'Gift items under 500' or 'Shampoo for dry hair'"
|
82 |
|
83 |
+
# Corrected reset_all function
|
84 |
def reset_all():
|
85 |
return (
|
86 |
None, None, None, None, None, None, None,
|
87 |
+
gr.update(choices=[], visible=False), # quantity dropdown reset
|
88 |
+
"", # result textbox reset
|
89 |
+
{} # data_state (gr.State) reset with raw dict, NOT gr.update()
|
90 |
)
|
91 |
|
92 |
# ----- UI -----
|
|
|
110 |
store_map = gr.Image(value=Image.open(DEFAULT_MAP), type="pil", label="πΊοΈ Store Map")
|
111 |
reset_btn = gr.Button("π Reset All")
|
112 |
|
113 |
+
# Dropdown chaining with consistent inputs and outputs
|
114 |
+
country.change(
|
115 |
+
lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)) if c else [], value=None),
|
116 |
+
inputs=country, outputs=state
|
117 |
+
)
|
118 |
+
state.change(
|
119 |
+
lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)) if c and s else [], value=None),
|
120 |
+
inputs=[country, state], outputs=city
|
121 |
+
)
|
122 |
+
city.change(
|
123 |
+
lambda c, s, ci: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci)) if c and s and ci else [], value=None),
|
124 |
+
inputs=[country, state, city], outputs=store
|
125 |
+
)
|
126 |
+
store.change(
|
127 |
+
lambda c, s, ci, st: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st)) if all([c, s, ci, st]) else [], value=None, interactive=True),
|
128 |
+
inputs=[country, state, city, store], outputs=category
|
129 |
+
)
|
130 |
+
category.change(
|
131 |
+
lambda c, s, ci, st, cat: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st, cat)) if all([c, s, ci, st, cat]) else [], value=None),
|
132 |
+
inputs=[country, state, city, store, category], outputs=product
|
133 |
+
)
|
134 |
+
product.change(
|
135 |
+
lambda c, s, ci, st, cat, prod: gr.update(choices=get_csv_files(os.path.join(BASE_DIR, c, s, ci, st, cat, prod)) if all([c, s, ci, st, cat, prod]) else [], value=None),
|
136 |
+
inputs=[country, state, city, store, category, product], outputs=brand
|
137 |
+
)
|
138 |
|
139 |
+
brand.change(
|
140 |
+
lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")) if all([c, s, ci, st, cat, prod, b]) else (gr.update(choices=[], visible=False), {}),
|
141 |
+
inputs=[country, state, city, store, category, product, brand],
|
142 |
+
outputs=[quantity, data_state]
|
143 |
+
)
|
144 |
|
145 |
+
quantity.change(
|
146 |
+
display_quantity_info,
|
147 |
+
inputs=[quantity, data_state],
|
148 |
+
outputs=result
|
149 |
+
)
|
150 |
|
151 |
+
product.change(
|
152 |
+
fn=get_product_image,
|
153 |
+
inputs=product,
|
154 |
+
outputs=store_map
|
155 |
+
)
|
156 |
|
157 |
reset_btn.click(
|
158 |
+
reset_all,
|
159 |
+
inputs=[],
|
160 |
+
outputs=[
|
161 |
+
country, state, city, store,
|
162 |
+
category, product, brand, quantity,
|
163 |
+
result, data_state
|
164 |
+
]
|
165 |
)
|
166 |
|
167 |
with gr.TabItem("π Smart Suggestions"):
|
|
|
170 |
suggest_btn = gr.Button("π‘ Get Suggestions")
|
171 |
suggestions_output = gr.Textbox(label="π Suggestions", lines=10)
|
172 |
|
173 |
+
suggest_btn.click(
|
174 |
+
suggest_items,
|
175 |
+
inputs=suggestion_input,
|
176 |
+
outputs=suggestions_output
|
177 |
+
)
|
178 |
|
179 |
demo.launch()
|