Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -41,13 +41,23 @@ def classify_comments():
|
|
41 |
# Gradio Interface
|
42 |
with gr.Blocks() as nps:
|
43 |
def add_category(category_list):
|
44 |
-
category_list.append(
|
45 |
return category_list
|
46 |
|
47 |
category_boxes = gr.State([]) # Store category input boxes as state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
category_column = gr.Row()
|
49 |
add_category_btn = gr.Button("Add Category")
|
50 |
add_category_btn.click(fn=add_category, inputs=[category_boxes], outputs=category_boxes)
|
|
|
51 |
uploaded_file = gr.File(label="Upload CSV", type="filepath")
|
52 |
template_btn = gr.Button("Use Template")
|
53 |
gr.Markdown("# NPS Comment Categorization")
|
@@ -75,8 +85,9 @@ with gr.Blocks() as nps:
|
|
75 |
uploaded_file.change(fn=load_data, inputs=uploaded_file, outputs=output)
|
76 |
template_btn.click(fn=lambda: "Using Template Dataset", outputs=output)
|
77 |
def use_template():
|
78 |
-
return [
|
79 |
template_btn.click(fn=use_template, outputs=category_boxes)
|
|
|
80 |
classify_btn.click(fn=classify_comments, inputs=category_boxes, outputs=output)
|
81 |
|
82 |
nps.launch()
|
|
|
41 |
# Gradio Interface
|
42 |
with gr.Blocks() as nps:
|
43 |
def add_category(category_list):
|
44 |
+
category_list.append("") # Add an empty category field
|
45 |
return category_list
|
46 |
|
47 |
category_boxes = gr.State([]) # Store category input boxes as state
|
48 |
+
def display_categories(categories):
|
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),
|
53 |
+
gr.Button("X", elem_id=f"remove_{i}")
|
54 |
+
])
|
55 |
+
components.append(row)
|
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")
|
63 |
gr.Markdown("# NPS Comment Categorization")
|
|
|
85 |
uploaded_file.change(fn=load_data, inputs=uploaded_file, outputs=output)
|
86 |
template_btn.click(fn=lambda: "Using Template Dataset", outputs=output)
|
87 |
def use_template():
|
88 |
+
return ["Product Experience", "Customer Support", "Price of Service", "Other"]
|
89 |
template_btn.click(fn=use_template, outputs=category_boxes)
|
90 |
+
category_boxes.change(fn=display_categories, inputs=category_boxes, outputs=category_column)
|
91 |
classify_btn.click(fn=classify_comments, inputs=category_boxes, outputs=output)
|
92 |
|
93 |
nps.launch()
|