Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,23 +4,25 @@ import pandas as pd
|
|
4 |
|
5 |
BASE_DIR = "data"
|
6 |
|
|
|
7 |
def get_subfolders(path):
|
8 |
-
print(f"
|
9 |
try:
|
10 |
-
|
11 |
-
print(f"β
Found: {folders}")
|
12 |
-
return folders
|
13 |
except Exception as e:
|
14 |
-
print(f"β Error
|
15 |
return []
|
16 |
|
17 |
-
|
18 |
def get_csv_files(path):
|
|
|
19 |
try:
|
20 |
return sorted([f[:-4] for f in os.listdir(path) if f.endswith(".csv")])
|
21 |
-
except
|
|
|
22 |
return []
|
23 |
|
|
|
24 |
def get_quantities_from_csv(path):
|
25 |
try:
|
26 |
df = pd.read_csv(path)
|
@@ -30,6 +32,7 @@ def get_quantities_from_csv(path):
|
|
30 |
except Exception as e:
|
31 |
return gr.update(choices=[], visible=False), {}
|
32 |
|
|
|
33 |
def display_quantity_info(quantity, data_dict):
|
34 |
try:
|
35 |
df = pd.DataFrame(data_dict)
|
@@ -46,40 +49,52 @@ def display_quantity_info(quantity, data_dict):
|
|
46 |
except Exception as e:
|
47 |
return f"β οΈ Error processing quantity info: {e}"
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
with gr.Blocks(title="RetailGenie Navigator") as demo:
|
50 |
gr.Markdown("## π§ RetailGenie β Multi-Store Smart Inventory Assistant")
|
51 |
|
52 |
with gr.Row():
|
53 |
country = gr.Dropdown(label="π Country", choices=get_subfolders(BASE_DIR), value=None)
|
54 |
-
state = gr.Dropdown(label="ποΈ State")
|
55 |
-
city = gr.Dropdown(label="ποΈ City")
|
56 |
-
store = gr.Dropdown(label="πͺ Store")
|
57 |
-
category = gr.Dropdown(label="ποΈ Category")
|
58 |
-
product = gr.Dropdown(label="π¦ Product")
|
59 |
-
brand = gr.Dropdown(label="π·οΈ Brand")
|
60 |
quantity = gr.Dropdown(label="π’ Quantity", visible=False)
|
61 |
|
62 |
result = gr.Textbox(label="π Product Info", lines=5)
|
63 |
data_state = gr.State()
|
64 |
|
65 |
-
|
|
|
|
|
66 |
country.change(
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
)
|
71 |
-
inputs=country,
|
72 |
-
outputs=state
|
73 |
-
)
|
74 |
|
75 |
state.change(
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
)
|
80 |
-
inputs=[country, state],
|
81 |
-
outputs=city
|
82 |
-
)
|
83 |
|
84 |
city.change(
|
85 |
lambda c, s, ci: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci)), value=None),
|
@@ -119,4 +134,10 @@ with gr.Blocks(title="RetailGenie Navigator") as demo:
|
|
119 |
outputs=result
|
120 |
)
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
demo.launch()
|
|
|
4 |
|
5 |
BASE_DIR = "data"
|
6 |
|
7 |
+
# Helper: Get subfolders at a given path
|
8 |
def get_subfolders(path):
|
9 |
+
print(f"π Reading subfolders from: {path}")
|
10 |
try:
|
11 |
+
return sorted([f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))])
|
|
|
|
|
12 |
except Exception as e:
|
13 |
+
print(f"β Error: {e}")
|
14 |
return []
|
15 |
|
16 |
+
# Helper: Get all .csv filenames (without .csv)
|
17 |
def get_csv_files(path):
|
18 |
+
print(f"π Reading CSV files from: {path}")
|
19 |
try:
|
20 |
return sorted([f[:-4] for f in os.listdir(path) if f.endswith(".csv")])
|
21 |
+
except Exception as e:
|
22 |
+
print(f"β Error: {e}")
|
23 |
return []
|
24 |
|
25 |
+
# Read CSV for brand and return available quantity options
|
26 |
def get_quantities_from_csv(path):
|
27 |
try:
|
28 |
df = pd.read_csv(path)
|
|
|
32 |
except Exception as e:
|
33 |
return gr.update(choices=[], visible=False), {}
|
34 |
|
35 |
+
# Show info based on selected quantity
|
36 |
def display_quantity_info(quantity, data_dict):
|
37 |
try:
|
38 |
df = pd.DataFrame(data_dict)
|
|
|
49 |
except Exception as e:
|
50 |
return f"β οΈ Error processing quantity info: {e}"
|
51 |
|
52 |
+
# Reset all fields
|
53 |
+
def reset_all():
|
54 |
+
return (
|
55 |
+
None, # country
|
56 |
+
None, # state
|
57 |
+
None, # city
|
58 |
+
None, # store
|
59 |
+
None, # category
|
60 |
+
None, # product
|
61 |
+
None, # brand
|
62 |
+
gr.update(choices=[], visible=False), # quantity
|
63 |
+
"", # result
|
64 |
+
{} # data state
|
65 |
+
)
|
66 |
+
|
67 |
+
# Interface
|
68 |
with gr.Blocks(title="RetailGenie Navigator") as demo:
|
69 |
gr.Markdown("## π§ RetailGenie β Multi-Store Smart Inventory Assistant")
|
70 |
|
71 |
with gr.Row():
|
72 |
country = gr.Dropdown(label="π Country", choices=get_subfolders(BASE_DIR), value=None)
|
73 |
+
state = gr.Dropdown(label="ποΈ State", value=None)
|
74 |
+
city = gr.Dropdown(label="ποΈ City", value=None)
|
75 |
+
store = gr.Dropdown(label="πͺ Store", value=None)
|
76 |
+
category = gr.Dropdown(label="ποΈ Category", value=None)
|
77 |
+
product = gr.Dropdown(label="π¦ Product", value=None)
|
78 |
+
brand = gr.Dropdown(label="π·οΈ Brand", value=None)
|
79 |
quantity = gr.Dropdown(label="π’ Quantity", visible=False)
|
80 |
|
81 |
result = gr.Textbox(label="π Product Info", lines=5)
|
82 |
data_state = gr.State()
|
83 |
|
84 |
+
reset_btn = gr.Button("π Reset All")
|
85 |
+
|
86 |
+
# Logic: Chain each dropdown to the next
|
87 |
country.change(
|
88 |
+
lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)), value=None),
|
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)), value=None),
|
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)), value=None),
|
|
|
134 |
outputs=result
|
135 |
)
|
136 |
|
137 |
+
reset_btn.click(
|
138 |
+
reset_all,
|
139 |
+
inputs=[],
|
140 |
+
outputs=[country, state, city, store, category, product, brand, quantity, result, data_state]
|
141 |
+
)
|
142 |
+
|
143 |
demo.launch()
|