Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -48,6 +48,13 @@ with gr.Blocks() as nps:
|
|
48 |
category_boxes = gr.State([]) # Store category input boxes as state
|
49 |
|
50 |
def display_categories(categories):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
category_column.children = [] # Reset children to clear previous categories
|
52 |
for i, cat in enumerate(categories):
|
53 |
with category_column:
|
@@ -65,6 +72,8 @@ with gr.Blocks() as nps:
|
|
65 |
with gr.Row():
|
66 |
category_input = gr.Textbox(label="New Category", placeholder="Enter category name")
|
67 |
add_category_btn = gr.Button("Add Category")
|
|
|
|
|
68 |
def remove_category(category, category_list):
|
69 |
category_list.remove(category) # Remove selected category
|
70 |
return category_list
|
|
|
48 |
category_boxes = gr.State([]) # Store category input boxes as state
|
49 |
|
50 |
def display_categories(categories):
|
51 |
+
category_column.children = [] # Clear previous categories
|
52 |
+
for i, cat in enumerate(categories):
|
53 |
+
with category_column:
|
54 |
+
with gr.Row():
|
55 |
+
gr.Markdown(f"- {cat}")
|
56 |
+
remove_btn = gr.Button("X", elem_id=f"remove_{i}", interactive=True)
|
57 |
+
remove_btn.click(fn=lambda x=cat: remove_category(x, categories), inputs=[], outputs=category_boxes)
|
58 |
category_column.children = [] # Reset children to clear previous categories
|
59 |
for i, cat in enumerate(categories):
|
60 |
with category_column:
|
|
|
72 |
with gr.Row():
|
73 |
category_input = gr.Textbox(label="New Category", placeholder="Enter category name")
|
74 |
add_category_btn = gr.Button("Add Category")
|
75 |
+
add_category_btn.click(fn=add_category, inputs=[category_boxes, category_input], outputs=category_boxes)
|
76 |
+
category_boxes.change(fn=display_categories, inputs=category_boxes, outputs=category_column)
|
77 |
def remove_category(category, category_list):
|
78 |
category_list.remove(category) # Remove selected category
|
79 |
return category_list
|