Parishri07 commited on
Commit
fc02939
·
verified ·
1 Parent(s): 75633af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -17
app.py CHANGED
@@ -57,10 +57,6 @@ def display_quantity_info(quantity, data_dict):
57
  except Exception as e:
58
  return f"⚠️ Error: {e}"
59
 
60
- def get_product_image(product_name):
61
- lower_name = product_name.strip().lower()
62
- return Image.open(PRODUCT_IMAGE_MAP.get(lower_name, DEFAULT_MAP))
63
-
64
  # Smart Suggestions Function
65
  def suggest_items(query):
66
  query = query.lower()
@@ -80,13 +76,12 @@ 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
- # 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 -----
@@ -107,10 +102,9 @@ with gr.Blocks(title="RetailGenie") as demo:
107
 
108
  result = gr.Textbox(label="🔍 Product Info", lines=5)
109
  data_state = gr.State()
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
@@ -135,25 +129,16 @@ with gr.Blocks(title="RetailGenie") as demo:
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=[],
 
57
  except Exception as e:
58
  return f"⚠️ Error: {e}"
59
 
 
 
 
 
60
  # Smart Suggestions Function
61
  def suggest_items(query):
62
  query = query.lower()
 
76
  )
77
  return "🤷 Sorry, no smart suggestions found. Try asking: 'Gift items under 500' or 'Shampoo for dry hair'"
78
 
 
79
  def reset_all():
80
  return (
81
  None, None, None, None, None, None, None,
82
  gr.update(choices=[], visible=False), # quantity dropdown reset
83
  "", # result textbox reset
84
+ {} # data_state (gr.State) reset with raw dict
85
  )
86
 
87
  # ----- UI -----
 
102
 
103
  result = gr.Textbox(label="🔍 Product Info", lines=5)
104
  data_state = gr.State()
 
105
  reset_btn = gr.Button("🔄 Reset All")
106
 
107
+ # Dropdown chaining
108
  country.change(
109
  lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)) if c else [], value=None),
110
  inputs=country, outputs=state
 
129
  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),
130
  inputs=[country, state, city, store, category, product], outputs=brand
131
  )
 
132
  brand.change(
133
  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), {}),
134
  inputs=[country, state, city, store, category, product, brand],
135
  outputs=[quantity, data_state]
136
  )
 
137
  quantity.change(
138
  display_quantity_info,
139
  inputs=[quantity, data_state],
140
  outputs=result
141
  )
 
 
 
 
 
 
 
142
  reset_btn.click(
143
  reset_all,
144
  inputs=[],