Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,40 +49,39 @@ def compute_pca(*args):
|
|
49 |
|
50 |
def text_editor_app():
|
51 |
with gr.Blocks() as demo:
|
52 |
-
num_pairs_visible = gr.State(value=4)
|
53 |
identifier_inputs = []
|
54 |
text_inputs = []
|
55 |
pair_rows = []
|
56 |
|
57 |
gr.Markdown("### Enter at least two identifier-text pairs:")
|
58 |
|
59 |
-
with gr.Column() as input_column:
|
60 |
-
for i in range(10): # Max 10 pairs
|
61 |
-
with gr.Column(visible=(i < 4)) as pair_row:
|
62 |
-
id_input = gr.Textbox(label=f"Identifier {i+1}")
|
63 |
-
text_input = gr.Textbox(label=f"Text {i+1}")
|
64 |
-
gr.Markdown("---") # Add a horizontal rule to create a break
|
65 |
-
identifier_inputs.append(id_input)
|
66 |
-
text_inputs.append(text_input)
|
67 |
-
pair_rows.append(pair_row)
|
68 |
-
|
69 |
add_pair_btn = gr.Button("Add Text")
|
70 |
analyze_button = gr.Button("Run Analysis")
|
71 |
output_plot = gr.Plot(label="PCA Visualization")
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# Function to collect inputs and process them
|
88 |
def collect_inputs(*args):
|
@@ -93,6 +92,7 @@ def text_editor_app():
|
|
93 |
data.append([identifier, text])
|
94 |
return compute_pca(*args)
|
95 |
|
|
|
96 |
inputs = []
|
97 |
for id_input, text_input in zip(identifier_inputs, text_inputs):
|
98 |
inputs.extend([id_input, text_input])
|
@@ -103,4 +103,3 @@ def text_editor_app():
|
|
103 |
|
104 |
# Launch the app
|
105 |
text_editor_app().launch()
|
106 |
-
|
|
|
49 |
|
50 |
def text_editor_app():
|
51 |
with gr.Blocks() as demo:
|
|
|
52 |
identifier_inputs = []
|
53 |
text_inputs = []
|
54 |
pair_rows = []
|
55 |
|
56 |
gr.Markdown("### Enter at least two identifier-text pairs:")
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
add_pair_btn = gr.Button("Add Text")
|
59 |
analyze_button = gr.Button("Run Analysis")
|
60 |
output_plot = gr.Plot(label="PCA Visualization")
|
61 |
|
62 |
+
max_pairs = 10 # Maximum number of pairs
|
63 |
+
initial_pairs = 4 # Initial number of visible pairs
|
64 |
+
|
65 |
+
# Create the input pairs
|
66 |
+
for i in range(max_pairs):
|
67 |
+
with gr.Column(visible=(i < initial_pairs)) as pair_row:
|
68 |
+
id_input = gr.Textbox(label=f"Identifier {i+1}")
|
69 |
+
text_input = gr.Textbox(label=f"Text {i+1}")
|
70 |
+
gr.Markdown("---") # Add a horizontal rule to create a break
|
71 |
+
identifier_inputs.append(id_input)
|
72 |
+
text_inputs.append(text_input)
|
73 |
+
pair_rows.append(pair_row)
|
74 |
|
75 |
+
# Function to add a new pair
|
76 |
+
def add_pair():
|
77 |
+
# Find the next invisible pair and make it visible
|
78 |
+
for pair_row in pair_rows:
|
79 |
+
if not pair_row.visible:
|
80 |
+
return gr.update(visible=True, value=None, interactive=True, component=pair_row)
|
81 |
+
return None # No more pairs to show
|
82 |
+
|
83 |
+
# Connect the add_pair function to the button
|
84 |
+
add_pair_btn.click(fn=add_pair, inputs=None, outputs=pair_rows)
|
85 |
|
86 |
# Function to collect inputs and process them
|
87 |
def collect_inputs(*args):
|
|
|
92 |
data.append([identifier, text])
|
93 |
return compute_pca(*args)
|
94 |
|
95 |
+
# Combine all inputs
|
96 |
inputs = []
|
97 |
for id_input, text_input in zip(identifier_inputs, text_inputs):
|
98 |
inputs.extend([id_input, text_input])
|
|
|
103 |
|
104 |
# Launch the app
|
105 |
text_editor_app().launch()
|
|