Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- config.py +10 -0
- ui/layout.py +11 -0
- ui/navigator_tab.py +0 -0
- ui/suggestions_tab.py +15 -0
- utils/data_utils.py +31 -0
- utils/file_utils.py +15 -0
- utils/suggest_utils.py +17 -0
config.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
BASE_DIR = "data"
|
4 |
+
ASSETS_DIR = "assets"
|
5 |
+
DEFAULT_MAP = os.path.join(ASSETS_DIR, "default_map.jpg")
|
6 |
+
PRODUCT_IMAGE_MAP = {
|
7 |
+
"shampoo": os.path.join(ASSETS_DIR, "shampoo_map.jpg"),
|
8 |
+
"curd": os.path.join(ASSETS_DIR, "curd_map.jpg"),
|
9 |
+
"ghee": os.path.join(ASSETS_DIR, "ghee_map.jpg")
|
10 |
+
}
|
ui/layout.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ui.navigator_tab import create_navigator_tab
|
3 |
+
from ui.suggestions_tab import create_suggestions_tab
|
4 |
+
|
5 |
+
def build_ui():
|
6 |
+
with gr.Blocks(title="RetailGenie") as demo:
|
7 |
+
gr.Markdown("# π§ββ RetailGenie β In-Store Smart Assistant")
|
8 |
+
with gr.Tabs():
|
9 |
+
create_navigator_tab()
|
10 |
+
create_suggestions_tab()
|
11 |
+
return demo
|
ui/navigator_tab.py
ADDED
File without changes
|
ui/suggestions_tab.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from utils.suggest_utils import suggest_items
|
3 |
+
|
4 |
+
def create_suggestions_tab():
|
5 |
+
with gr.TabItem("π Smart Suggestions"):
|
6 |
+
gr.Markdown("### π€ Ask RetailGenie for Recommendations")
|
7 |
+
suggestion_input = gr.Textbox(label="Ask something like:", placeholder="Gift items under 500", lines=1)
|
8 |
+
suggest_btn = gr.Button("π‘ Get Suggestions")
|
9 |
+
suggestions_output = gr.Textbox(label="π Suggestions", lines=10)
|
10 |
+
|
11 |
+
suggest_btn.click(
|
12 |
+
suggest_items,
|
13 |
+
inputs=suggestion_input,
|
14 |
+
outputs=suggestions_output
|
15 |
+
)
|
utils/data_utils.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def get_quantities_from_csv(path):
|
5 |
+
try:
|
6 |
+
df = pd.read_csv(path)
|
7 |
+
if df.empty or "Quantity" not in df.columns:
|
8 |
+
return gr.update(choices=[], visible=False), {}
|
9 |
+
return gr.update(choices=df["Quantity"].dropna().tolist(), visible=True), df.to_dict()
|
10 |
+
except Exception as e:
|
11 |
+
print(f"β Error loading CSV: {e}")
|
12 |
+
return gr.update(choices=[], visible=False), {}
|
13 |
+
|
14 |
+
def display_quantity_info(quantity, data_dict):
|
15 |
+
try:
|
16 |
+
df = pd.DataFrame(data_dict)
|
17 |
+
row = df[df["Quantity"] == quantity].iloc[0]
|
18 |
+
if str(row["In Stock"]).strip().lower() == "yes":
|
19 |
+
msg = (
|
20 |
+
f"β
{quantity} is available!\n"
|
21 |
+
f"β’ Floor: {row['Floor']}\n"
|
22 |
+
f"β’ Aisle: {row['Aisle']}\n"
|
23 |
+
f"β’ Price: βΉ{row['Price']}"
|
24 |
+
)
|
25 |
+
if "Offer" in row and pd.notna(row["Offer"]) and row["Offer"].strip():
|
26 |
+
msg += f"\nβ’ π Offer: {row['Offer']}"
|
27 |
+
return msg
|
28 |
+
else:
|
29 |
+
return f"β Sorry, {quantity} is currently not in stock."
|
30 |
+
except Exception as e:
|
31 |
+
return f"β Error: {e}"
|
utils/file_utils.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
def get_subfolders(path):
|
4 |
+
try:
|
5 |
+
return sorted([f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))])
|
6 |
+
except Exception as e:
|
7 |
+
print(f"β Error reading subfolders from {path}: {e}")
|
8 |
+
return []
|
9 |
+
|
10 |
+
def get_csv_files(path):
|
11 |
+
try:
|
12 |
+
return sorted([f[:-4] for f in os.listdir(path) if f.endswith(".csv")])
|
13 |
+
except Exception as e:
|
14 |
+
print(f"β Error reading CSVs from {path}: {e}")
|
15 |
+
return []
|
utils/suggest_utils.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def suggest_items(query):
|
2 |
+
query = query.lower()
|
3 |
+
if "gift" in query and "500" in query:
|
4 |
+
return (
|
5 |
+
"π Gift Suggestions under βΉ500:\n"
|
6 |
+
"1. Bath & Body Gift Set - βΉ499\n"
|
7 |
+
"2. Mini Perfume Pack - βΉ349\n"
|
8 |
+
"3. Skin Care Hamper - βΉ399\n"
|
9 |
+
"4. Chocolates Gift Box - βΉ299"
|
10 |
+
)
|
11 |
+
if "shampoo" in query and "dry" in query:
|
12 |
+
return (
|
13 |
+
"π§΄ Shampoos for Dry Hair:\n"
|
14 |
+
"1. Dove 500 ml - βΉ325\n"
|
15 |
+
"2. Clinic Plus 500 ml - βΉ680"
|
16 |
+
)
|
17 |
+
return "π€· Sorry, no smart suggestions found. Try asking: 'Gift items under 500' or 'Shampoo for dry hair'"
|