Parishri07 commited on
Commit
75633af
Β·
verified Β·
1 Parent(s): 8d9d683

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -22
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(lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)) if c else [], value=None), inputs=country, outputs=state)
115
- state.change(lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)) if c and s else [], value=None), inputs=[country, state], outputs=city)
116
- city.change(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), inputs=[country, state, city], outputs=store)
117
- store.change(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), inputs=[country, state, city, store], outputs=category)
118
- category.change(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), inputs=[country, state, city, store, category], outputs=product)
119
- product.change(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), inputs=[country, state, city, store, category, product], outputs=brand)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
- brand.change(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), {}), inputs=[country, state, city, store, category, product, brand], outputs=[quantity, data_state])
 
 
 
 
122
 
123
- quantity.change(display_quantity_info, inputs=[quantity, data_state], outputs=result)
 
 
 
 
124
 
125
- product.change(fn=get_product_image, inputs=product, outputs=store_map)
 
 
 
 
126
 
127
  reset_btn.click(
128
- reset_all,
129
- inputs=[],
130
- outputs=[
131
- country, state, city, store,
132
- category, product, brand, quantity,
133
- result, data_state
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(suggest_items, inputs=suggestion_input, outputs=suggestions_output)
 
 
 
 
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()