Parishri07 commited on
Commit
7b02833
Β·
verified Β·
1 Parent(s): 5b1e3c4

Update ui/navigator_tab.py

Browse files
Files changed (1) hide show
  1. ui/navigator_tab.py +49 -16
ui/navigator_tab.py CHANGED
@@ -3,6 +3,7 @@ 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
  def reset_all():
7
  return (
8
  None, # country
@@ -13,28 +14,63 @@ def reset_all():
13
  None, # product
14
  None, # brand
15
  gr.update(choices=[], visible=False), # quantity
16
- "", # result Textbox
17
- {} # data_state (Gradio state)
18
  )
19
 
20
-
21
  def create_navigator_tab():
22
  with gr.TabItem("🧭 Navigator"):
23
  with gr.Row():
24
- country = gr.Dropdown(...)
25
- state = gr.Dropdown(...)
26
- city = gr.Dropdown(...)
27
- store = gr.Dropdown(...)
28
- category = gr.Dropdown(...)
29
- product = gr.Dropdown(...)
30
- brand = gr.Dropdown(...)
31
- quantity = gr.Dropdown(...)
32
 
33
- result = gr.Textbox(...)
34
  data_state = gr.State()
35
  reset_btn = gr.Button("πŸ”„ Reset All")
36
 
37
- # Bind reset_btn here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  reset_btn.click(
39
  reset_all,
40
  inputs=[],
@@ -44,6 +80,3 @@ def create_navigator_tab():
44
  result, data_state
45
  ]
46
  )
47
-
48
- # πŸ›‘ IMPORTANT: return all these so layout.py can receive them
49
- return country, state, city, store, category, product, brand, quantity, result, data_state, reset_btn
 
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
 
14
  None, # product
15
  None, # brand
16
  gr.update(choices=[], visible=False), # quantity
17
+ "", # result box
18
+ {} # state
19
  )
20
 
21
+ # Main UI builder
22
  def create_navigator_tab():
23
  with gr.TabItem("🧭 Navigator"):
24
  with gr.Row():
25
+ country = gr.Dropdown(label="🌍 Country", choices=get_subfolders(BASE_DIR), interactive=True)
26
+ state = gr.Dropdown(label="πŸ™ State", choices=[], interactive=True)
27
+ city = gr.Dropdown(label="🏘 City", choices=[], interactive=True)
28
+ store = gr.Dropdown(label="πŸͺ Store", choices=[], interactive=True)
29
+ category = gr.Dropdown(label="πŸ› Category", choices=[], interactive=True)
30
+ product = gr.Dropdown(label="πŸ“¦ Product", choices=[], interactive=True)
31
+ brand = gr.Dropdown(label="🏷 Brand", choices=[], interactive=True)
32
+ quantity = gr.Dropdown(label="πŸ”’ Quantity", choices=[], visible=False, interactive=True)
33
 
34
+ result = gr.Textbox(label="πŸ” Product Info", lines=5)
35
  data_state = gr.State()
36
  reset_btn = gr.Button("πŸ”„ Reset All")
37
 
38
+ # Dropdown chaining logic
39
+ country.change(
40
+ lambda c: gr.update(choices=get_subfolders(f"{BASE_DIR}/{c}") if c else [], value=None),
41
+ inputs=country, outputs=state
42
+ )
43
+ state.change(
44
+ lambda c, s: gr.update(choices=get_subfolders(f"{BASE_DIR}/{c}/{s}") if c and s else [], value=None),
45
+ inputs=[country, state], outputs=city
46
+ )
47
+ city.change(
48
+ lambda c, s, ci: gr.update(choices=get_subfolders(f"{BASE_DIR}/{c}/{s}/{ci}") if c and s and ci else [], value=None),
49
+ inputs=[country, state, city], outputs=store
50
+ )
51
+ store.change(
52
+ 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),
53
+ inputs=[country, state, city, store], outputs=category
54
+ )
55
+ category.change(
56
+ 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),
57
+ inputs=[country, state, city, store, category], outputs=product
58
+ )
59
+ product.change(
60
+ 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),
61
+ inputs=[country, state, city, store, category, product], outputs=brand
62
+ )
63
+ brand.change(
64
+ 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), {}),
65
+ inputs=[country, state, city, store, category, product, brand],
66
+ outputs=[quantity, data_state]
67
+ )
68
+ quantity.change(
69
+ display_quantity_info,
70
+ inputs=[quantity, data_state],
71
+ outputs=result
72
+ )
73
+
74
  reset_btn.click(
75
  reset_all,
76
  inputs=[],
 
80
  result, data_state
81
  ]
82
  )