Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- ui/__init__.py +0 -0
- ui/layout.py +51 -0
- ui/navigator_tab.py +88 -0
- ui/suggestions_tab.py +66 -0
ui/__init__.py
ADDED
|
File without changes
|
ui/layout.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ui.navigator_tab import create_navigator_tab, load_initial_country_choices
|
| 3 |
+
from ui.suggestions_tab import create_suggestions_tab
|
| 4 |
+
|
| 5 |
+
def build_ui():
|
| 6 |
+
with gr.Blocks(title="RetailGenie") as demo:
|
| 7 |
+
# β
Global CSS
|
| 8 |
+
gr.HTML(
|
| 9 |
+
"""
|
| 10 |
+
<style>
|
| 11 |
+
.centered-text {
|
| 12 |
+
text-align: center;
|
| 13 |
+
font-size: 16px;
|
| 14 |
+
font-weight: 500;
|
| 15 |
+
margin-bottom: 12px;
|
| 16 |
+
}
|
| 17 |
+
#main-wrapper {
|
| 18 |
+
max-width: 1000px;
|
| 19 |
+
margin: 0 auto;
|
| 20 |
+
padding: 20px;
|
| 21 |
+
}
|
| 22 |
+
</style>
|
| 23 |
+
"""
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# π§Ύ Disclaimer
|
| 27 |
+
gr.Markdown(
|
| 28 |
+
"""
|
| 29 |
+
<div style="background-color:#2a2a2a; padding: 15px; border-radius: 10px; border: 1px solid #444; text-align: center; font-size: 14px; color: #ddd;">
|
| 30 |
+
β <strong>Disclaimer:</strong> <strong>RetailGenie</strong> is a prototype developed for <strong>educational and demonstration purposes only</strong>. Product suggestions, availability, and store locations are based on <strong>sample data</strong> and may not reflect real-time inventory.<br><br>
|
| 31 |
+
π <strong>Note:</strong> Some responses may take a few seconds due to model inference and file processing within a constrained development environment.
|
| 32 |
+
</div>
|
| 33 |
+
""",
|
| 34 |
+
elem_classes="centered-text"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# π§ββ Title
|
| 38 |
+
gr.Markdown("# π§ββ RetailGenie β In-Store Smart Assistant", elem_classes="centered-text")
|
| 39 |
+
|
| 40 |
+
# π‘ Tabs
|
| 41 |
+
with gr.Tabs():
|
| 42 |
+
country_dropdown, = create_navigator_tab()
|
| 43 |
+
create_suggestions_tab()
|
| 44 |
+
|
| 45 |
+
# π Footer
|
| 46 |
+
gr.Markdown("Made by TEAM AtoMβ‘", elem_classes="centered-text")
|
| 47 |
+
|
| 48 |
+
# π Load country dropdown choices without default selection
|
| 49 |
+
demo.load(fn=load_initial_country_choices, inputs=None, outputs=country_dropdown)
|
| 50 |
+
|
| 51 |
+
return demo
|
ui/navigator_tab.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from config import BASE_DIR
|
| 3 |
+
from utils.file_utils import get_subfolders, get_csv_files
|
| 4 |
+
from utils.data_utils import get_quantities_from_csv, display_quantity_info
|
| 5 |
+
|
| 6 |
+
# Reset logic
|
| 7 |
+
def reset_all():
|
| 8 |
+
return (
|
| 9 |
+
None, # country
|
| 10 |
+
None, # state
|
| 11 |
+
None, # city
|
| 12 |
+
None, # store
|
| 13 |
+
None, # category
|
| 14 |
+
None, # product
|
| 15 |
+
None, # brand
|
| 16 |
+
gr.update(choices=[], visible=False), # quantity
|
| 17 |
+
"", # result box
|
| 18 |
+
{} # state
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Load choices on app load
|
| 22 |
+
def load_initial_country_choices():
|
| 23 |
+
return gr.update(choices=get_subfolders(BASE_DIR), value=None)
|
| 24 |
+
|
| 25 |
+
# Main UI builder
|
| 26 |
+
def create_navigator_tab():
|
| 27 |
+
with gr.TabItem("π§ Navigator"):
|
| 28 |
+
with gr.Row():
|
| 29 |
+
country = gr.Dropdown(label="π Country", choices=[], interactive=True)
|
| 30 |
+
state = gr.Dropdown(label="π State", choices=[], interactive=True)
|
| 31 |
+
city = gr.Dropdown(label="π City", choices=[], interactive=True)
|
| 32 |
+
store = gr.Dropdown(label="πͺ Store", choices=[], interactive=True)
|
| 33 |
+
category = gr.Dropdown(label="π Category", choices=[], interactive=True)
|
| 34 |
+
product = gr.Dropdown(label="π¦ Product", choices=[], interactive=True)
|
| 35 |
+
brand = gr.Dropdown(label="π· Brand", choices=[], interactive=True)
|
| 36 |
+
quantity = gr.Dropdown(label="π’ Quantity", choices=[], visible=False, interactive=True)
|
| 37 |
+
|
| 38 |
+
result = gr.Textbox(label="π Product Info", lines=5)
|
| 39 |
+
data_state = gr.State()
|
| 40 |
+
reset_btn = gr.Button("π Reset All")
|
| 41 |
+
|
| 42 |
+
# Dropdown chaining logic
|
| 43 |
+
country.change(
|
| 44 |
+
lambda c: gr.update(choices=get_subfolders(f"{BASE_DIR}/{c}") if c else [], value=None),
|
| 45 |
+
inputs=country, outputs=state
|
| 46 |
+
)
|
| 47 |
+
state.change(
|
| 48 |
+
lambda c, s: gr.update(choices=get_subfolders(f"{BASE_DIR}/{c}/{s}") if c and s else [], value=None),
|
| 49 |
+
inputs=[country, state], outputs=city
|
| 50 |
+
)
|
| 51 |
+
city.change(
|
| 52 |
+
lambda c, s, ci: gr.update(choices=get_subfolders(f"{BASE_DIR}/{c}/{s}/{ci}") if c and s and ci else [], value=None),
|
| 53 |
+
inputs=[country, state, city], outputs=store
|
| 54 |
+
)
|
| 55 |
+
store.change(
|
| 56 |
+
lambda c, s, ci, st: gr.update(choices=get_subfolders(f"{BASE_DIR}/{c}/{s}/{ci}/{st}") if all([c, s, ci, st]) else [], value=None),
|
| 57 |
+
inputs=[country, state, city, store], outputs=category
|
| 58 |
+
)
|
| 59 |
+
category.change(
|
| 60 |
+
lambda c, s, ci, st, cat: gr.update(choices=get_subfolders(f"{BASE_DIR}/{c}/{s}/{ci}/{st}/{cat}") if all([c, s, ci, st, cat]) else [], value=None),
|
| 61 |
+
inputs=[country, state, city, store, category], outputs=product
|
| 62 |
+
)
|
| 63 |
+
product.change(
|
| 64 |
+
lambda c, s, ci, st, cat, prod: gr.update(choices=get_csv_files(f"{BASE_DIR}/{c}/{s}/{ci}/{st}/{cat}/{prod}") if all([c, s, ci, st, cat, prod]) else [], value=None),
|
| 65 |
+
inputs=[country, state, city, store, category, product], outputs=brand
|
| 66 |
+
)
|
| 67 |
+
brand.change(
|
| 68 |
+
lambda c, s, ci, st, cat, prod, b: get_quantities_from_csv(f"{BASE_DIR}/{c}/{s}/{ci}/{st}/{cat}/{prod}/{b}.csv") if all([c, s, ci, st, cat, prod, b]) else (gr.update(choices=[], visible=False), {}),
|
| 69 |
+
inputs=[country, state, city, store, category, product, brand],
|
| 70 |
+
outputs=[quantity, data_state]
|
| 71 |
+
)
|
| 72 |
+
quantity.change(
|
| 73 |
+
display_quantity_info,
|
| 74 |
+
inputs=[quantity, data_state],
|
| 75 |
+
outputs=result
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
reset_btn.click(
|
| 79 |
+
reset_all,
|
| 80 |
+
inputs=[],
|
| 81 |
+
outputs=[
|
| 82 |
+
country, state, city, store,
|
| 83 |
+
category, product, brand, quantity,
|
| 84 |
+
result, data_state
|
| 85 |
+
]
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
return country, # so we can use it in demo.load() from layout.py
|
ui/suggestions_tab.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from smart_suggestion.flan_suggestor import generate_product_description
|
| 3 |
+
|
| 4 |
+
def create_suggestions_tab():
|
| 5 |
+
with gr.TabItem("π Smart Suggestions"):
|
| 6 |
+
# π· Header
|
| 7 |
+
gr.Markdown(
|
| 8 |
+
"""
|
| 9 |
+
## π€ Ask RetailGenie for Recommendations
|
| 10 |
+
π§ Just type your need β e.g., _"shampoo for dry hair under 500"_, _"gift sets"_, or _"budget skin care"_
|
| 11 |
+
and let Genie do the rest!
|
| 12 |
+
""",
|
| 13 |
+
elem_classes="centered-text"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# π© Input Section
|
| 17 |
+
suggestion_input = gr.Textbox(
|
| 18 |
+
label="π¬ Your Request",
|
| 19 |
+
placeholder="Try: Gifts under 500, or Shampoo for dry hair",
|
| 20 |
+
lines=1
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
gr.Markdown("<div style='margin-top: 8px;'></div>")
|
| 24 |
+
|
| 25 |
+
# π¦ Button
|
| 26 |
+
suggest_btn = gr.Button("π Get Suggestions")
|
| 27 |
+
|
| 28 |
+
gr.Markdown("<div style='margin-top: 12px;'></div>")
|
| 29 |
+
|
| 30 |
+
# π¨ Output Section
|
| 31 |
+
suggestions_output = gr.Textbox(
|
| 32 |
+
label="β¨ Suggested Products",
|
| 33 |
+
lines=10,
|
| 34 |
+
interactive=False,
|
| 35 |
+
show_copy_button=True,
|
| 36 |
+
elem_id="suggestion-box"
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# π§ Connect logic to FLAN model
|
| 40 |
+
suggest_btn.click(
|
| 41 |
+
fn=generate_product_description,
|
| 42 |
+
inputs=suggestion_input,
|
| 43 |
+
outputs=suggestions_output
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# π
CSS for centered text and consistent spacing
|
| 47 |
+
gr.Markdown(
|
| 48 |
+
"""
|
| 49 |
+
<style>
|
| 50 |
+
.centered-text {
|
| 51 |
+
text-align: center;
|
| 52 |
+
font-size: 16px;
|
| 53 |
+
font-weight: 500;
|
| 54 |
+
}
|
| 55 |
+
#suggestion-box textarea {
|
| 56 |
+
font-family: 'Courier New', monospace;
|
| 57 |
+
font-size: 14px;
|
| 58 |
+
background-color: #111827;
|
| 59 |
+
color: #e5e7eb;
|
| 60 |
+
border-radius: 10px;
|
| 61 |
+
padding: 10px;
|
| 62 |
+
white-space: pre-line; /* important for preserving line breaks */
|
| 63 |
+
}
|
| 64 |
+
</style>
|
| 65 |
+
"""
|
| 66 |
+
)
|