Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,79 @@
|
|
1 |
-
import pandas as pd
|
2 |
import gradio as gr
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
df = pd.read_csv("inventory.csv")
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
if str(row["In Stock"]).strip().lower() == "yes":
|
21 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
else:
|
23 |
-
return f"β
|
24 |
-
|
25 |
-
return "β οΈ
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
return gr.update(value=None), gr.update(choices=[], visible=False), "", ""
|
30 |
-
|
31 |
-
# Gradio App
|
32 |
-
with gr.Blocks(title="RetailGenie") as demo:
|
33 |
-
gr.Markdown("## π§ RetailGenie β Your Smart In-Store Assistant")
|
34 |
-
gr.Markdown("### π Welcome! Let me help you quickly find products in your store.")
|
35 |
|
36 |
with gr.Row():
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
message = gr.Textbox(label="π¬ Assistant Response", interactive=False)
|
44 |
|
45 |
# Logic chaining
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
|
52 |
demo.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
BASE_DIR = "data"
|
|
|
6 |
|
7 |
+
def get_subfolders(path):
|
8 |
+
try:
|
9 |
+
return sorted([f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))])
|
10 |
+
except FileNotFoundError:
|
11 |
+
return []
|
12 |
|
13 |
+
def get_csv_files(path):
|
14 |
+
try:
|
15 |
+
return sorted([f[:-4] for f in os.listdir(path) if f.endswith(".csv")])
|
16 |
+
except FileNotFoundError:
|
17 |
+
return []
|
18 |
|
19 |
+
def load_csv_info(path):
|
20 |
+
try:
|
21 |
+
df = pd.read_csv(path)
|
22 |
+
if df.empty:
|
23 |
+
return "β οΈ No data found in the selected brand file."
|
24 |
+
row = df.iloc[0]
|
25 |
if str(row["In Stock"]).strip().lower() == "yes":
|
26 |
+
return (
|
27 |
+
f"β
{os.path.basename(path).replace('.csv', '')} is in stock.\n"
|
28 |
+
f"- Quantity: {row['Quantity']}\n"
|
29 |
+
f"- Floor: {row['Floor']}\n"
|
30 |
+
f"- Aisle: {row['Aisle']}\n"
|
31 |
+
f"- Price: βΉ{row['Price']}"
|
32 |
+
)
|
33 |
else:
|
34 |
+
return f"β {os.path.basename(path).replace('.csv', '')} is currently out of stock."
|
35 |
+
except Exception as e:
|
36 |
+
return f"β οΈ Error reading CSV: {e}"
|
37 |
|
38 |
+
with gr.Blocks(title="RetailGenie Navigator") as demo:
|
39 |
+
gr.Markdown("## π§ RetailGenie β Multi-Store Smart Inventory Assistant")
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
with gr.Row():
|
42 |
+
country = gr.Dropdown(label="π Country", choices=get_subfolders(BASE_DIR))
|
43 |
+
state = gr.Dropdown(label="ποΈ State")
|
44 |
+
city = gr.Dropdown(label="ποΈ City")
|
45 |
+
store = gr.Dropdown(label="πͺ Store")
|
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 |
|
52 |
# Logic chaining
|
53 |
+
country.change(lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)), value=None),
|
54 |
+
inputs=country, outputs=state)
|
55 |
+
|
56 |
+
state.change(lambda c, s: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s)), value=None),
|
57 |
+
inputs=[country, state], outputs=city)
|
58 |
+
|
59 |
+
city.change(lambda c, s, ci: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci)), value=None),
|
60 |
+
inputs=[country, state, city], outputs=store)
|
61 |
+
|
62 |
+
store.change(lambda c, s, ci, st: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st)), value=None),
|
63 |
+
inputs=[country, state, city, store], outputs=category)
|
64 |
+
|
65 |
+
category.change(lambda c, s, ci, st, cat: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st, cat)), value=None),
|
66 |
+
inputs=[country, state, city, store, category], outputs=product)
|
67 |
+
|
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: load_csv_info(
|
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 |
|
79 |
demo.launch()
|