Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -40,13 +40,24 @@ def classify_comments():
|
|
40 |
|
41 |
# Gradio Interface
|
42 |
with gr.Blocks() as nps:
|
43 |
-
def add_category(category_list):
|
44 |
-
|
|
|
45 |
return category_list
|
46 |
|
47 |
category_boxes = gr.State([]) # Store category input boxes as state
|
48 |
-
|
|
|
|
|
|
|
49 |
components = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
for i, cat in enumerate(categories):
|
51 |
row = gr.Row([
|
52 |
gr.Textbox(value=cat, label=f"Category {i+1}", interactive=True),
|
@@ -56,7 +67,7 @@ with gr.Blocks() as nps:
|
|
56 |
return components
|
57 |
category_column = gr.Row()
|
58 |
add_category_btn = gr.Button("Add Category")
|
59 |
-
add_category_btn.click(fn=add_category, inputs=[category_boxes], outputs=category_boxes)
|
60 |
category_boxes.change(fn=display_categories, inputs=category_boxes, outputs=category_column)
|
61 |
uploaded_file = gr.File(label="Upload CSV", type="filepath")
|
62 |
template_btn = gr.Button("Use Template")
|
|
|
40 |
|
41 |
# Gradio Interface
|
42 |
with gr.Blocks() as nps:
|
43 |
+
def add_category(category_list, new_category):
|
44 |
+
if new_category.strip() != "":
|
45 |
+
category_list.append(new_category.strip()) # Add new category
|
46 |
return category_list
|
47 |
|
48 |
category_boxes = gr.State([]) # Store category input boxes as state
|
49 |
+
category_input = gr.Textbox(label="New Category", placeholder="Enter category name")
|
50 |
+
def remove_category(category, category_list):
|
51 |
+
category_list.remove(category) # Remove selected category
|
52 |
+
return category_list
|
53 |
components = []
|
54 |
+
for i, cat in enumerate(categories):
|
55 |
+
row = gr.Row([
|
56 |
+
gr.Markdown(f"- {cat}"),
|
57 |
+
gr.Button("X", elem_id=f"remove_{i}", interactive=True).click(fn=lambda x=cat: remove_category(x, categories), inputs=[], outputs=category_boxes)
|
58 |
+
])
|
59 |
+
components.append(row)
|
60 |
+
return components
|
61 |
for i, cat in enumerate(categories):
|
62 |
row = gr.Row([
|
63 |
gr.Textbox(value=cat, label=f"Category {i+1}", interactive=True),
|
|
|
67 |
return components
|
68 |
category_column = gr.Row()
|
69 |
add_category_btn = gr.Button("Add Category")
|
70 |
+
add_category_btn.click(fn=add_category, inputs=[category_boxes, category_input], outputs=category_boxes)
|
71 |
category_boxes.change(fn=display_categories, inputs=category_boxes, outputs=category_column)
|
72 |
uploaded_file = gr.File(label="Upload CSV", type="filepath")
|
73 |
template_btn = gr.Button("Use Template")
|