Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,24 +16,30 @@ def get_csv_files(path):
|
|
16 |
except FileNotFoundError:
|
17 |
return []
|
18 |
|
19 |
-
def
|
20 |
try:
|
21 |
df = pd.read_csv(path)
|
22 |
-
if df.empty:
|
23 |
-
return
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
if str(row["In Stock"]).strip().lower() == "yes":
|
26 |
return (
|
27 |
-
f"β
{
|
28 |
-
f"
|
29 |
-
f"
|
30 |
-
f"
|
31 |
-
f"- Price: βΉ{row['Price']}"
|
32 |
)
|
33 |
else:
|
34 |
-
return f"β
|
35 |
except Exception as e:
|
36 |
-
return f"β οΈ Error
|
37 |
|
38 |
with gr.Blocks(title="RetailGenie Navigator") as demo:
|
39 |
gr.Markdown("## π§ RetailGenie β Multi-Store Smart Inventory Assistant")
|
@@ -46,6 +52,7 @@ with gr.Blocks(title="RetailGenie Navigator") as demo:
|
|
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 |
|
@@ -68,11 +75,19 @@ with gr.Blocks(title="RetailGenie Navigator") as demo:
|
|
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:
|
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 |
|
|
|
16 |
except FileNotFoundError:
|
17 |
return []
|
18 |
|
19 |
+
def get_quantities_from_csv(path):
|
20 |
try:
|
21 |
df = pd.read_csv(path)
|
22 |
+
if df.empty or "Quantity" not in df.columns:
|
23 |
+
return gr.update(choices=[], visible=False), gr.State({})
|
24 |
+
return gr.update(choices=df["Quantity"].dropna().tolist(), visible=True), df.to_dict()
|
25 |
+
except Exception as e:
|
26 |
+
return gr.update(choices=[], visible=False), gr.State({})
|
27 |
+
|
28 |
+
def display_quantity_info(quantity, data_dict):
|
29 |
+
try:
|
30 |
+
df = pd.DataFrame(data_dict)
|
31 |
+
row = df[df["Quantity"] == quantity].iloc[0]
|
32 |
if str(row["In Stock"]).strip().lower() == "yes":
|
33 |
return (
|
34 |
+
f"β
{quantity} is available!\n"
|
35 |
+
f"β’ Floor: {row['Floor']}\n"
|
36 |
+
f"β’ Aisle: {row['Aisle']}\n"
|
37 |
+
f"β’ Price: βΉ{row['Price']}"
|
|
|
38 |
)
|
39 |
else:
|
40 |
+
return f"β Sorry, {quantity} is currently not in stock."
|
41 |
except Exception as e:
|
42 |
+
return f"β οΈ Error processing quantity info: {e}"
|
43 |
|
44 |
with gr.Blocks(title="RetailGenie Navigator") as demo:
|
45 |
gr.Markdown("## π§ RetailGenie β Multi-Store Smart Inventory Assistant")
|
|
|
52 |
category = gr.Dropdown(label="ποΈ Category")
|
53 |
product = gr.Dropdown(label="π¦ Product")
|
54 |
brand = gr.Dropdown(label="π·οΈ Brand")
|
55 |
+
quantity = gr.Dropdown(label="π’ Quantity", visible=False)
|
56 |
|
57 |
result = gr.Textbox(label="π Product Info", lines=5)
|
58 |
|
|
|
75 |
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),
|
76 |
inputs=[country, state, city, store, category, product], outputs=brand)
|
77 |
|
78 |
+
# When brand is selected β get quantities + dataframe state
|
79 |
brand.change(
|
80 |
+
lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(
|
81 |
os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")
|
82 |
),
|
83 |
inputs=[country, state, city, store, category, product, brand],
|
84 |
+
outputs=[quantity, gr.State()]
|
85 |
+
)
|
86 |
+
|
87 |
+
# When quantity is selected β lookup and display info
|
88 |
+
quantity.change(
|
89 |
+
display_quantity_info,
|
90 |
+
inputs=[quantity, gr.State()],
|
91 |
outputs=result
|
92 |
)
|
93 |
|