gloignon commited on
Commit
47c5583
·
verified ·
1 Parent(s): f44d635

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -41,29 +41,29 @@ def compute_pca(data):
41
 
42
  def text_editor_app():
43
  with gr.Blocks() as demo:
44
- # Use a DataFrame component for inputs with fixed columns
45
- data_input = gr.Dataframe(
46
- headers=["Identifier", "Text"],
47
- datatype=["str", "str"],
48
- row_count=(4, "dynamic"),
49
- col_count=(2, "fixed"),
50
- label="Input Data (Enter at least two texts)",
51
- wrap=True
52
- )
53
 
54
- # Button to run the analysis
55
  analyze_button = gr.Button("Run Analysis")
56
-
57
- # Output plot
58
  output_plot = gr.Plot(label="PCA Visualization")
59
 
60
- # Run analysis when the button is clicked
61
- analyze_button.click(
62
- fn=compute_pca, inputs=data_input, outputs=output_plot
63
- )
 
 
64
 
65
  return demo
66
 
67
 
 
68
  # Launch the app
69
  text_editor_app().launch()
 
41
 
42
  def text_editor_app():
43
  with gr.Blocks() as demo:
44
+ identifiers = []
45
+ texts = []
46
+ with gr.Row():
47
+ for i in range(4): # Assuming 4 entries
48
+ with gr.Column():
49
+ id_input = gr.Textbox(label=f"Identifier {i+1}")
50
+ text_input = gr.Textbox(label=f"Text {i+1}")
51
+ identifiers.append(id_input)
52
+ texts.append(text_input)
53
 
 
54
  analyze_button = gr.Button("Run Analysis")
 
 
55
  output_plot = gr.Plot(label="PCA Visualization")
56
 
57
+ def collect_inputs(*args):
58
+ data = list(zip(args[:4], args[4:])) # Pair identifiers and texts
59
+ return compute_pca(data)
60
+
61
+ inputs = identifiers + texts
62
+ analyze_button.click(fn=collect_inputs, inputs=inputs, outputs=output_plot)
63
 
64
  return demo
65
 
66
 
67
+
68
  # Launch the app
69
  text_editor_app().launch()