Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,10 +20,10 @@ 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),
|
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),
|
27 |
|
28 |
def display_quantity_info(quantity, data_dict):
|
29 |
try:
|
@@ -55,10 +55,14 @@ with gr.Blocks(title="RetailGenie Navigator") as demo:
|
|
55 |
quantity = gr.Dropdown(label="π’ Quantity", visible=False)
|
56 |
|
57 |
result = gr.Textbox(label="π Product Info", lines=5)
|
|
|
58 |
|
59 |
# Logic chaining
|
60 |
-
country.change(
|
61 |
-
|
|
|
|
|
|
|
62 |
|
63 |
state.change(
|
64 |
lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)), value=None),
|
@@ -66,31 +70,41 @@ with gr.Blocks(title="RetailGenie Navigator") as demo:
|
|
66 |
outputs=city
|
67 |
)
|
68 |
|
69 |
-
city.change(
|
70 |
-
|
|
|
|
|
|
|
71 |
|
72 |
-
store.change(
|
73 |
-
|
|
|
|
|
|
|
74 |
|
75 |
-
category.change(
|
76 |
-
|
|
|
|
|
|
|
77 |
|
78 |
-
product.change(
|
79 |
-
|
|
|
|
|
|
|
80 |
|
81 |
-
# When brand is selected β get quantities + dataframe state
|
82 |
brand.change(
|
83 |
lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(
|
84 |
os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")
|
85 |
),
|
86 |
inputs=[country, state, city, store, category, product, brand],
|
87 |
-
outputs=[quantity,
|
88 |
)
|
89 |
|
90 |
-
# When quantity is selected β lookup and display info
|
91 |
quantity.change(
|
92 |
display_quantity_info,
|
93 |
-
inputs=[quantity,
|
94 |
outputs=result
|
95 |
)
|
96 |
|
|
|
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), {}
|
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), {}
|
27 |
|
28 |
def display_quantity_info(quantity, data_dict):
|
29 |
try:
|
|
|
55 |
quantity = gr.Dropdown(label="π’ Quantity", visible=False)
|
56 |
|
57 |
result = gr.Textbox(label="π Product Info", lines=5)
|
58 |
+
data_state = gr.State()
|
59 |
|
60 |
# Logic chaining
|
61 |
+
country.change(
|
62 |
+
lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)), value=None),
|
63 |
+
inputs=country,
|
64 |
+
outputs=state
|
65 |
+
)
|
66 |
|
67 |
state.change(
|
68 |
lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)), value=None),
|
|
|
70 |
outputs=city
|
71 |
)
|
72 |
|
73 |
+
city.change(
|
74 |
+
lambda c, s, ci: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci)), value=None),
|
75 |
+
inputs=[country, state, city],
|
76 |
+
outputs=store
|
77 |
+
)
|
78 |
|
79 |
+
store.change(
|
80 |
+
lambda c, s, ci, st: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st)), value=None),
|
81 |
+
inputs=[country, state, city, store],
|
82 |
+
outputs=category
|
83 |
+
)
|
84 |
|
85 |
+
category.change(
|
86 |
+
lambda c, s, ci, st, cat: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st, cat)), value=None),
|
87 |
+
inputs=[country, state, city, store, category],
|
88 |
+
outputs=product
|
89 |
+
)
|
90 |
|
91 |
+
product.change(
|
92 |
+
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),
|
93 |
+
inputs=[country, state, city, store, category, product],
|
94 |
+
outputs=brand
|
95 |
+
)
|
96 |
|
|
|
97 |
brand.change(
|
98 |
lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(
|
99 |
os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")
|
100 |
),
|
101 |
inputs=[country, state, city, store, category, product, brand],
|
102 |
+
outputs=[quantity, data_state]
|
103 |
)
|
104 |
|
|
|
105 |
quantity.change(
|
106 |
display_quantity_info,
|
107 |
+
inputs=[quantity, data_state],
|
108 |
outputs=result
|
109 |
)
|
110 |
|