Parishri07 commited on
Commit
03931e3
Β·
verified Β·
1 Parent(s): 7d40776

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -69
app.py CHANGED
@@ -39,15 +39,22 @@ def display_quantity_info(quantity, data_dict):
39
  if str(row["In Stock"]).strip().lower() == "yes":
40
  return (
41
  f"βœ… {quantity} is available!\n"
42
- f"β€’ Floor: {row['Floor']}\n"
43
- f"β€’ Aisle: {row['Aisle']}\n"
44
- f"β€’ Price: β‚Ή{row['Price']}"
45
  )
46
  else:
47
  return f"❌ Sorry, {quantity} is currently not in stock."
48
  except Exception as e:
49
  return f"⚠️ Error: {e}"
50
 
 
 
 
 
 
 
 
51
  # Reset all
52
  def reset_all():
53
  return (
@@ -55,79 +62,83 @@ def reset_all():
55
  gr.update(choices=[], visible=False), "", {}
56
  )
57
 
58
- # Interface
59
- with gr.Blocks(title="RetailGenie Navigator") as demo:
60
- gr.Markdown("## 🧞 RetailGenie – Multi-Store Smart Inventory Assistant")
61
-
62
- with gr.Row():
63
- country = gr.Dropdown(label="🌍 Country", choices=get_subfolders(BASE_DIR), value=None)
64
- state = gr.Dropdown(label="πŸ™οΈ State", choices=[], interactive=False)
65
- city = gr.Dropdown(label="🏘️ City", choices=[], interactive=False)
66
- store = gr.Dropdown(label="πŸͺ Store", choices=[], interactive=False)
67
- category = gr.Dropdown(label="πŸ›οΈ Category", choices=[], interactive=False)
68
- product = gr.Dropdown(label="πŸ“¦ Product", choices=[], interactive=False)
69
- brand = gr.Dropdown(label="🏷️ Brand", choices=[], interactive=False)
70
- quantity = gr.Dropdown(label="πŸ”’ Quantity", visible=False)
71
-
72
- result = gr.Textbox(label="πŸ” Product Info", lines=5)
73
- data_state = gr.State()
74
- reset_btn = gr.Button("πŸ”„ Reset All")
75
-
76
- # Logic chaining with safety checks
77
- country.change(
78
- lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)) if c else [], value=None, interactive=True),
79
- inputs=country,
80
- outputs=state
81
- )
 
 
 
82
 
83
- state.change(
84
- lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)) if c and s else [], value=None, interactive=True),
85
- inputs=[country, state],
86
- outputs=city
87
- )
88
 
89
- city.change(
90
- 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, interactive=True),
91
- inputs=[country, state, city],
92
- outputs=store
93
- )
94
 
95
- store.change(
96
- lambda c, s, ci, st: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st)) if c and s and ci and st else [], value=None, interactive=True),
97
- inputs=[country, state, city, store],
98
- outputs=category
99
- )
100
 
101
- category.change(
102
- lambda c, s, ci, st, cat: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st, cat)) if c and s and ci and st and cat else [], value=None, interactive=True),
103
- inputs=[country, state, city, store, category],
104
- outputs=product
105
- )
106
 
107
- product.change(
108
- 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 c and s and ci and st and cat and prod else [], value=None, interactive=True),
109
- inputs=[country, state, city, store, category, product],
110
- outputs=brand
111
- )
112
 
113
- brand.change(
114
- lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(
115
- os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")
116
- ) if all([c, s, ci, st, cat, prod, b]) else (gr.update(choices=[], visible=False), {}),
117
- inputs=[country, state, city, store, category, product, brand],
118
- outputs=[quantity, data_state]
119
- )
120
 
121
- quantity.change(
122
- display_quantity_info,
123
- inputs=[quantity, data_state],
124
- outputs=result
125
- )
126
 
127
- reset_btn.click(
128
- reset_all,
129
- inputs=[],
130
- outputs=[country, state, city, store, category, product, brand, quantity, result, data_state]
131
- )
 
 
 
 
 
132
 
133
  demo.launch()
 
39
  if str(row["In Stock"]).strip().lower() == "yes":
40
  return (
41
  f"βœ… {quantity} is available!\n"
42
+ f"\u2022 Floor: {row['Floor']}\n"
43
+ f"\u2022 Aisle: {row['Aisle']}\n"
44
+ f"\u2022 Price: β‚Ή{row['Price']}"
45
  )
46
  else:
47
  return f"❌ Sorry, {quantity} is currently not in stock."
48
  except Exception as e:
49
  return f"⚠️ Error: {e}"
50
 
51
+ # Dummy AI suggestion function
52
+ def suggest_items(query):
53
+ query = query.lower()
54
+ if "gift" in query and "500" in query:
55
+ return "1. Bath & Body Gift Set - β‚Ή499\n2. Mini Perfume Pack - β‚Ή349\n3. Skin Care Hamper - β‚Ή399"
56
+ return "🎁 Sorry, no suggestions found for your query. Try something like: 'Gift items under 500'"
57
+
58
  # Reset all
59
  def reset_all():
60
  return (
 
62
  gr.update(choices=[], visible=False), "", {}
63
  )
64
 
65
+ # Interface with Tabs
66
+ with gr.Blocks(title="RetailGenie") as demo:
67
+ gr.Markdown("# πŸ§žβ€β™‚οΈ RetailGenie – In-Store Smart Assistant")
68
+
69
+ with gr.Tabs():
70
+ # ---------------- Tab 1: Navigator ----------------
71
+ with gr.TabItem("🧭 Navigator"):
72
+ with gr.Row():
73
+ country = gr.Dropdown(label="🌍 Country", choices=get_subfolders(BASE_DIR), value=None)
74
+ state = gr.Dropdown(label="πŸŒ† State", choices=[], interactive=False)
75
+ city = gr.Dropdown(label="🏘️ City", choices=[], interactive=False)
76
+ store = gr.Dropdown(label="πŸͺ Store", choices=[], interactive=False)
77
+ category = gr.Dropdown(label="🏍️ Category", choices=[], interactive=False)
78
+ product = gr.Dropdown(label="πŸ“¦ Product", choices=[], interactive=False)
79
+ brand = gr.Dropdown(label="🏷️ Brand", choices=[], interactive=False)
80
+ quantity = gr.Dropdown(label="πŸ”’ Quantity", visible=False)
81
+
82
+ result = gr.Textbox(label="πŸ” Product Info", lines=5)
83
+ data_state = gr.State()
84
+ reset_btn = gr.Button("πŸ”„ Reset All")
85
+
86
+ # Dropdown logic
87
+ country.change(
88
+ lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)) if c else [], value=None, interactive=True),
89
+ inputs=country,
90
+ outputs=state
91
+ )
92
 
93
+ state.change(
94
+ lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)) if c and s else [], value=None, interactive=True),
95
+ inputs=[country, state],
96
+ outputs=city
97
+ )
98
 
99
+ city.change(
100
+ 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, interactive=True),
101
+ inputs=[country, state, city],
102
+ outputs=store
103
+ )
104
 
105
+ store.change(
106
+ 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),
107
+ inputs=[country, state, city, store],
108
+ outputs=category
109
+ )
110
 
111
+ category.change(
112
+ 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, interactive=True),
113
+ inputs=[country, state, city, store, category],
114
+ outputs=product
115
+ )
116
 
117
+ product.change(
118
+ 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, interactive=True),
119
+ inputs=[country, state, city, store, category, product],
120
+ outputs=brand
121
+ )
122
 
123
+ brand.change(
124
+ lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(
125
+ os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")
126
+ ) if all([c, s, ci, st, cat, prod, b]) else (gr.update(choices=[], visible=False), {}),
127
+ inputs=[country, state, city, store, category, product, brand],
128
+ outputs=[quantity, data_state]
129
+ )
130
 
131
+ quantity.change(display_quantity_info, inputs=[quantity, data_state], outputs=result)
 
 
 
 
132
 
133
+ reset_btn.click(reset_all, inputs=[], outputs=[country, state, city, store, category, product, brand, quantity, result, data_state])
134
+
135
+ # ---------------- Tab 2: Smart Suggestions ----------------
136
+ with gr.TabItem("🎁 Smart Suggestions"):
137
+ gr.Markdown("### πŸ€– Ask RetailGenie for Recommendations")
138
+ suggestion_input = gr.Textbox(label="Ask something like:", placeholder="Gift items under 500", lines=1)
139
+ suggest_btn = gr.Button("πŸ’‘ Get Suggestions")
140
+ suggestions_output = gr.Textbox(label="πŸ“ Suggestions", lines=10)
141
+
142
+ suggest_btn.click(suggest_items, inputs=suggestion_input, outputs=suggestions_output)
143
 
144
  demo.launch()