Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,62 +52,60 @@ def display_quantity_info(quantity, data_dict):
|
|
52 |
def reset_all():
|
53 |
return (
|
54 |
None, None, None, None, None, None, None,
|
55 |
-
gr.update(choices=[], visible=False),
|
56 |
-
"", {}
|
57 |
)
|
58 |
|
59 |
-
#
|
60 |
with gr.Blocks(title="RetailGenie Navigator") as demo:
|
61 |
gr.Markdown("## π§ RetailGenie β Multi-Store Smart Inventory Assistant")
|
62 |
|
63 |
with gr.Row():
|
64 |
country = gr.Dropdown(label="π Country", choices=get_subfolders(BASE_DIR), value=None)
|
65 |
-
state = gr.Dropdown(label="ποΈ State", choices=[],
|
66 |
-
city = gr.Dropdown(label="ποΈ City", choices=[],
|
67 |
-
store = gr.Dropdown(label="πͺ Store", choices=[],
|
68 |
-
category = gr.Dropdown(label="ποΈ Category", choices=[],
|
69 |
-
product = gr.Dropdown(label="π¦ Product", choices=[],
|
70 |
-
brand = gr.Dropdown(label="π·οΈ Brand", choices=[],
|
71 |
quantity = gr.Dropdown(label="π’ Quantity", visible=False)
|
72 |
|
73 |
result = gr.Textbox(label="π Product Info", lines=5)
|
74 |
data_state = gr.State()
|
75 |
-
|
76 |
reset_btn = gr.Button("π Reset All")
|
77 |
|
78 |
-
# Logic chaining
|
79 |
country.change(
|
80 |
-
lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)), value=None, interactive=True),
|
81 |
inputs=country,
|
82 |
outputs=state
|
83 |
)
|
84 |
|
85 |
state.change(
|
86 |
-
lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)), value=None, interactive=True),
|
87 |
inputs=[country, state],
|
88 |
outputs=city
|
89 |
)
|
90 |
|
91 |
city.change(
|
92 |
-
lambda c, s, ci: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci)), value=None, interactive=True),
|
93 |
inputs=[country, state, city],
|
94 |
outputs=store
|
95 |
)
|
96 |
|
97 |
store.change(
|
98 |
-
lambda c, s, ci, st: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st)), value=None, interactive=True),
|
99 |
inputs=[country, state, city, store],
|
100 |
outputs=category
|
101 |
)
|
102 |
|
103 |
category.change(
|
104 |
-
lambda c, s, ci, st, cat: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st, cat)), value=None, interactive=True),
|
105 |
inputs=[country, state, city, store, category],
|
106 |
outputs=product
|
107 |
)
|
108 |
|
109 |
product.change(
|
110 |
-
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, interactive=True),
|
111 |
inputs=[country, state, city, store, category, product],
|
112 |
outputs=brand
|
113 |
)
|
@@ -115,7 +113,7 @@ with gr.Blocks(title="RetailGenie Navigator") as demo:
|
|
115 |
brand.change(
|
116 |
lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(
|
117 |
os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")
|
118 |
-
),
|
119 |
inputs=[country, state, city, store, category, product, brand],
|
120 |
outputs=[quantity, data_state]
|
121 |
)
|
|
|
52 |
def reset_all():
|
53 |
return (
|
54 |
None, None, None, None, None, None, None,
|
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 |
)
|
|
|
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 |
)
|