Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,15 +39,22 @@ def display_quantity_info(quantity, data_dict):
|
|
39 |
if str(row["In Stock"]).strip().lower() == "yes":
|
40 |
return (
|
41 |
f"β
{quantity} is available!\n"
|
42 |
-
f"
|
43 |
-
f"
|
44 |
-
f"
|
45 |
)
|
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 (
|
@@ -55,79 +62,83 @@ def reset_all():
|
|
55 |
gr.update(choices=[], visible=False), "", {}
|
56 |
)
|
57 |
|
58 |
-
# Interface
|
59 |
-
with gr.Blocks(title="RetailGenie
|
60 |
-
gr.Markdown("
|
61 |
-
|
62 |
-
with gr.
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
|
121 |
-
|
122 |
-
display_quantity_info,
|
123 |
-
inputs=[quantity, data_state],
|
124 |
-
outputs=result
|
125 |
-
)
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
demo.launch()
|
|
|
39 |
if str(row["In Stock"]).strip().lower() == "yes":
|
40 |
return (
|
41 |
f"β
{quantity} is available!\n"
|
42 |
+
f"\u2022 Floor: {row['Floor']}\n"
|
43 |
+
f"\u2022 Aisle: {row['Aisle']}\n"
|
44 |
+
f"\u2022 Price: βΉ{row['Price']}"
|
45 |
)
|
46 |
else:
|
47 |
return f"β Sorry, {quantity} is currently not in stock."
|
48 |
except Exception as e:
|
49 |
return f"β οΈ Error: {e}"
|
50 |
|
51 |
+
# Dummy AI suggestion function
|
52 |
+
def suggest_items(query):
|
53 |
+
query = query.lower()
|
54 |
+
if "gift" in query and "500" in query:
|
55 |
+
return "1. Bath & Body Gift Set - βΉ499\n2. Mini Perfume Pack - βΉ349\n3. Skin Care Hamper - βΉ399"
|
56 |
+
return "π Sorry, no suggestions found for your query. Try something like: 'Gift items under 500'"
|
57 |
+
|
58 |
# Reset all
|
59 |
def reset_all():
|
60 |
return (
|
|
|
62 |
gr.update(choices=[], visible=False), "", {}
|
63 |
)
|
64 |
|
65 |
+
# Interface with Tabs
|
66 |
+
with gr.Blocks(title="RetailGenie") as demo:
|
67 |
+
gr.Markdown("# π§ββοΈ RetailGenie β In-Store Smart Assistant")
|
68 |
+
|
69 |
+
with gr.Tabs():
|
70 |
+
# ---------------- Tab 1: Navigator ----------------
|
71 |
+
with gr.TabItem("π§ Navigator"):
|
72 |
+
with gr.Row():
|
73 |
+
country = gr.Dropdown(label="π Country", choices=get_subfolders(BASE_DIR), value=None)
|
74 |
+
state = gr.Dropdown(label="π State", choices=[], interactive=False)
|
75 |
+
city = gr.Dropdown(label="ποΈ City", choices=[], interactive=False)
|
76 |
+
store = gr.Dropdown(label="πͺ Store", choices=[], interactive=False)
|
77 |
+
category = gr.Dropdown(label="ποΈ Category", choices=[], interactive=False)
|
78 |
+
product = gr.Dropdown(label="π¦ Product", choices=[], interactive=False)
|
79 |
+
brand = gr.Dropdown(label="π·οΈ Brand", choices=[], interactive=False)
|
80 |
+
quantity = gr.Dropdown(label="π’ Quantity", visible=False)
|
81 |
+
|
82 |
+
result = gr.Textbox(label="π Product Info", lines=5)
|
83 |
+
data_state = gr.State()
|
84 |
+
reset_btn = gr.Button("π Reset All")
|
85 |
+
|
86 |
+
# Dropdown logic
|
87 |
+
country.change(
|
88 |
+
lambda c: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c)) if c else [], value=None, interactive=True),
|
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)) if c and s else [], value=None, interactive=True),
|
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)) if c and s and ci else [], value=None, interactive=True),
|
101 |
+
inputs=[country, state, city],
|
102 |
+
outputs=store
|
103 |
+
)
|
104 |
|
105 |
+
store.change(
|
106 |
+
lambda c, s, ci, st: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st)) if all([c,s,ci,st]) else [], value=None, interactive=True),
|
107 |
+
inputs=[country, state, city, store],
|
108 |
+
outputs=category
|
109 |
+
)
|
110 |
|
111 |
+
category.change(
|
112 |
+
lambda c, s, ci, st, cat: gr.update(choices=get_subfolders(os.path.join(BASE_DIR, c, s, ci, st, cat)) if all([c,s,ci,st,cat]) else [], value=None, interactive=True),
|
113 |
+
inputs=[country, state, city, store, category],
|
114 |
+
outputs=product
|
115 |
+
)
|
116 |
|
117 |
+
product.change(
|
118 |
+
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 all([c,s,ci,st,cat,prod]) else [], value=None, interactive=True),
|
119 |
+
inputs=[country, state, city, store, category, product],
|
120 |
+
outputs=brand
|
121 |
+
)
|
122 |
|
123 |
+
brand.change(
|
124 |
+
lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(
|
125 |
+
os.path.join(BASE_DIR, c, s, ci, st, cat, prod, f"{b}.csv")
|
126 |
+
) if all([c, s, ci, st, cat, prod, b]) else (gr.update(choices=[], visible=False), {}),
|
127 |
+
inputs=[country, state, city, store, category, product, brand],
|
128 |
+
outputs=[quantity, data_state]
|
129 |
+
)
|
130 |
|
131 |
+
quantity.change(display_quantity_info, inputs=[quantity, data_state], outputs=result)
|
|
|
|
|
|
|
|
|
132 |
|
133 |
+
reset_btn.click(reset_all, inputs=[], outputs=[country, state, city, store, category, product, brand, quantity, result, data_state])
|
134 |
+
|
135 |
+
# ---------------- Tab 2: Smart Suggestions ----------------
|
136 |
+
with gr.TabItem("π Smart Suggestions"):
|
137 |
+
gr.Markdown("### π€ Ask RetailGenie for Recommendations")
|
138 |
+
suggestion_input = gr.Textbox(label="Ask something like:", placeholder="Gift items under 500", lines=1)
|
139 |
+
suggest_btn = gr.Button("π‘ Get Suggestions")
|
140 |
+
suggestions_output = gr.Textbox(label="π Suggestions", lines=10)
|
141 |
+
|
142 |
+
suggest_btn.click(suggest_items, inputs=suggestion_input, outputs=suggestions_output)
|
143 |
|
144 |
demo.launch()
|