Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,25 +4,23 @@ import pandas as pd
|
|
4 |
|
5 |
BASE_DIR = "data"
|
6 |
|
7 |
-
#
|
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 |
-
#
|
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 |
-
#
|
26 |
def get_quantities_from_csv(path):
|
27 |
try:
|
28 |
df = pd.read_csv(path)
|
@@ -30,9 +28,10 @@ def get_quantities_from_csv(path):
|
|
30 |
return gr.update(choices=[], visible=False), {}
|
31 |
return gr.update(choices=df["Quantity"].dropna().tolist(), visible=True), df.to_dict()
|
32 |
except Exception as e:
|
|
|
33 |
return gr.update(choices=[], visible=False), {}
|
34 |
|
35 |
-
# Show
|
36 |
def display_quantity_info(quantity, data_dict):
|
37 |
try:
|
38 |
df = pd.DataFrame(data_dict)
|
@@ -47,45 +46,38 @@ def display_quantity_info(quantity, data_dict):
|
|
47 |
else:
|
48 |
return f"β Sorry, {quantity} is currently not in stock."
|
49 |
except Exception as e:
|
50 |
-
return f"β οΈ Error
|
51 |
|
52 |
-
# Reset all
|
53 |
def reset_all():
|
54 |
return (
|
55 |
-
None,
|
56 |
-
|
57 |
-
|
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 |
-
#
|
68 |
with gr.Blocks(title="RetailGenie Navigator") as demo:
|
69 |
gr.Markdown("## π§ RetailGenie β Multi-Store Smart Inventory Assistant")
|
70 |
|
71 |
with gr.Row():
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
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
|
87 |
country.change(
|
88 |
-
lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)), value=None,interactive=True),
|
89 |
inputs=country,
|
90 |
outputs=state
|
91 |
)
|
|
|
4 |
|
5 |
BASE_DIR = "data"
|
6 |
|
7 |
+
# Get subfolders
|
8 |
def get_subfolders(path):
|
|
|
9 |
try:
|
10 |
return sorted([f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))])
|
11 |
except Exception as e:
|
12 |
+
print(f"β Error reading subfolders from {path}: {e}")
|
13 |
return []
|
14 |
|
15 |
+
# Get CSV files
|
16 |
def get_csv_files(path):
|
|
|
17 |
try:
|
18 |
return sorted([f[:-4] for f in os.listdir(path) if f.endswith(".csv")])
|
19 |
except Exception as e:
|
20 |
+
print(f"β Error reading CSVs from {path}: {e}")
|
21 |
return []
|
22 |
|
23 |
+
# Load quantities from brand CSV
|
24 |
def get_quantities_from_csv(path):
|
25 |
try:
|
26 |
df = pd.read_csv(path)
|
|
|
28 |
return gr.update(choices=[], visible=False), {}
|
29 |
return gr.update(choices=df["Quantity"].dropna().tolist(), visible=True), df.to_dict()
|
30 |
except Exception as e:
|
31 |
+
print(f"β Error loading CSV: {e}")
|
32 |
return gr.update(choices=[], visible=False), {}
|
33 |
|
34 |
+
# Show result based on quantity
|
35 |
def display_quantity_info(quantity, data_dict):
|
36 |
try:
|
37 |
df = pd.DataFrame(data_dict)
|
|
|
46 |
else:
|
47 |
return f"β Sorry, {quantity} is currently not in stock."
|
48 |
except Exception as e:
|
49 |
+
return f"β οΈ Error: {e}"
|
50 |
|
51 |
+
# Reset all
|
52 |
def reset_all():
|
53 |
return (
|
54 |
+
None, None, None, None, None, None, None,
|
55 |
+
gr.update(choices=[], visible=False),
|
56 |
+
"", {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
)
|
58 |
|
59 |
+
# UI
|
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=[], visible=True, interactive=False)
|
66 |
+
city = gr.Dropdown(label="ποΈ City", choices=[], visible=True, interactive=False)
|
67 |
+
store = gr.Dropdown(label="πͺ Store", choices=[], visible=True, interactive=False)
|
68 |
+
category = gr.Dropdown(label="ποΈ Category", choices=[], visible=True, interactive=False)
|
69 |
+
product = gr.Dropdown(label="π¦ Product", choices=[], visible=True, interactive=False)
|
70 |
+
brand = gr.Dropdown(label="π·οΈ Brand", choices=[], visible=True, interactive=False)
|
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 |
)
|