Parishri07 commited on
Commit
e406115
Β·
verified Β·
1 Parent(s): 20ff6eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -36
app.py CHANGED
@@ -1,52 +1,79 @@
1
- import pandas as pd
2
  import gradio as gr
 
 
3
 
4
- # Load data
5
- df = pd.read_csv("inventory.csv")
6
 
7
- # Get category list
8
- categories = sorted(df['Category'].dropna().unique())
 
 
 
9
 
10
- # Product selector from category
11
- def get_products(category):
12
- products = df[df['Category'] == category]['Product Name'].unique().tolist()
13
- return gr.update(choices=products, visible=True), category
 
14
 
15
- # Final result message
16
- def get_product_info(product, category):
17
- match = df[(df['Category'] == category) & (df['Product Name'] == product)]
18
- if not match.empty:
19
- row = match.iloc[0]
 
20
  if str(row["In Stock"]).strip().lower() == "yes":
21
- return f"βœ… {product} is available in Aisle {row['Aisle']}. We have {row['Quantity']} in stock, and it's priced at β‚Ή{row['Price (rupees)']}."
 
 
 
 
 
 
22
  else:
23
- return f"❌ Sorry, {product} is currently not available in stock."
24
- else:
25
- return "⚠️ Product not found."
26
 
27
- # Clear function
28
- def reset():
29
- return gr.update(value=None), gr.update(choices=[], visible=False), "", ""
30
-
31
- # Gradio App
32
- with gr.Blocks(title="RetailGenie") as demo:
33
- gr.Markdown("## 🧞 RetailGenie – Your Smart In-Store Assistant")
34
- gr.Markdown("### πŸ‘‹ Welcome! Let me help you quickly find products in your store.")
35
 
36
  with gr.Row():
37
- with gr.Column():
38
- category_input = gr.Dropdown(label="πŸ—‚οΈ Choose Product Category", choices=categories)
39
- product_input = gr.Dropdown(label="πŸ“¦ Choose a Product", visible=False)
40
- clear_btn = gr.Button("πŸ” Start Over")
 
 
 
41
 
42
- with gr.Column():
43
- message = gr.Textbox(label="πŸ’¬ Assistant Response", interactive=False)
44
 
45
  # Logic chaining
46
- state_category = gr.State()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- category_input.change(get_products, inputs=category_input, outputs=[product_input, state_category])
49
- product_input.change(get_product_info, inputs=[product_input, state_category], outputs=message)
50
- clear_btn.click(reset, outputs=[category_input, product_input, message, state_category])
 
 
 
 
51
 
52
  demo.launch()
 
 
1
  import gradio as gr
2
+ import os
3
+ import pandas as pd
4
 
5
+ BASE_DIR = "data"
 
6
 
7
+ def get_subfolders(path):
8
+ try:
9
+ return sorted([f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))])
10
+ except FileNotFoundError:
11
+ return []
12
 
13
+ def get_csv_files(path):
14
+ try:
15
+ return sorted([f[:-4] for f in os.listdir(path) if f.endswith(".csv")])
16
+ except FileNotFoundError:
17
+ return []
18
 
19
+ def load_csv_info(path):
20
+ try:
21
+ df = pd.read_csv(path)
22
+ if df.empty:
23
+ return "⚠️ No data found in the selected brand file."
24
+ row = df.iloc[0]
25
  if str(row["In Stock"]).strip().lower() == "yes":
26
+ return (
27
+ f"βœ… {os.path.basename(path).replace('.csv', '')} is in stock.\n"
28
+ f"- Quantity: {row['Quantity']}\n"
29
+ f"- Floor: {row['Floor']}\n"
30
+ f"- Aisle: {row['Aisle']}\n"
31
+ f"- Price: β‚Ή{row['Price']}"
32
+ )
33
  else:
34
+ return f"❌ {os.path.basename(path).replace('.csv', '')} is currently out of stock."
35
+ except Exception as e:
36
+ return f"⚠️ Error reading CSV: {e}"
37
 
38
+ with gr.Blocks(title="RetailGenie Navigator") as demo:
39
+ gr.Markdown("## 🧞 RetailGenie – Multi-Store Smart Inventory Assistant")
 
 
 
 
 
 
40
 
41
  with gr.Row():
42
+ country = gr.Dropdown(label="🌍 Country", choices=get_subfolders(BASE_DIR))
43
+ state = gr.Dropdown(label="πŸ™οΈ State")
44
+ city = gr.Dropdown(label="🏘️ City")
45
+ store = gr.Dropdown(label="πŸͺ Store")
46
+ category = gr.Dropdown(label="πŸ›οΈ Category")
47
+ product = gr.Dropdown(label="πŸ“¦ Product")
48
+ brand = gr.Dropdown(label="🏷️ Brand")
49
 
50
+ result = gr.Textbox(label="πŸ” Product Info", lines=5)
 
51
 
52
  # Logic chaining
53
+ country.change(lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)), value=None),
54
+ inputs=country, outputs=state)
55
+
56
+ state.change(lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)), value=None),
57
+ inputs=[country, state], outputs=city)
58
+
59
+ city.change(lambda c, s, ci: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci)), value=None),
60
+ inputs=[country, state, city], outputs=store)
61
+
62
+ store.change(lambda c, s, ci, st: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st)), value=None),
63
+ inputs=[country, state, city, store], outputs=category)
64
+
65
+ category.change(lambda c, s, ci, st, cat: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st, cat)), value=None),
66
+ inputs=[country, state, city, store, category], outputs=product)
67
+
68
+ 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)), value=None),
69
+ inputs=[country, state, city, store, category, product], outputs=brand)
70
 
71
+ brand.change(
72
+ lambda c, s, ci, st, cat, prod, b: load_csv_info(
73
+ os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")
74
+ ),
75
+ inputs=[country, state, city, store, category, product, brand],
76
+ outputs=result
77
+ )
78
 
79
  demo.launch()