gloignon commited on
Commit
11f43b6
·
verified ·
1 Parent(s): 5c5f1db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -44,6 +44,9 @@ def text_editor_app():
44
  with gr.Blocks() as demo:
45
  identifier_inputs = []
46
  text_inputs = []
 
 
 
47
  for i in range(4): # Assuming we have 4 entries
48
  with gr.Column():
49
  id_input = gr.Textbox(label=f"Identifier {i+1}")
@@ -52,19 +55,33 @@ def text_editor_app():
52
  text_inputs.append(text_input)
53
  gr.Markdown("---") # Add a horizontal rule to create a break
54
 
 
55
  analyze_button = gr.Button("Run Analysis")
 
 
56
  output_plot = gr.Plot(label="PCA Visualization")
57
 
 
58
  def collect_inputs(*args):
59
- data = list(zip(args[:4], args[4:])) # Pair identifiers and texts
 
 
 
 
 
 
60
  return compute_pca(data)
61
 
62
- inputs = identifiers + texts
 
 
 
63
  analyze_button.click(fn=collect_inputs, inputs=inputs, outputs=output_plot)
64
 
65
  return demo
66
 
67
 
68
 
 
69
  # Launch the app
70
  text_editor_app().launch()
 
44
  with gr.Blocks() as demo:
45
  identifier_inputs = []
46
  text_inputs = []
47
+
48
+ gr.Markdown("### Enter at least two identifier-text pairs:")
49
+
50
  for i in range(4): # Assuming we have 4 entries
51
  with gr.Column():
52
  id_input = gr.Textbox(label=f"Identifier {i+1}")
 
55
  text_inputs.append(text_input)
56
  gr.Markdown("---") # Add a horizontal rule to create a break
57
 
58
+ # Button to run the analysis
59
  analyze_button = gr.Button("Run Analysis")
60
+
61
+ # Output plot
62
  output_plot = gr.Plot(label="PCA Visualization")
63
 
64
+ # Function to collect inputs and process them
65
  def collect_inputs(*args):
66
+ # args will be identifier1, text1, identifier2, text2, ..., identifier4, text4
67
+ # So we need to pair them up
68
+ data = []
69
+ for i in range(0, len(args), 2):
70
+ identifier = args[i]
71
+ text = args[i+1]
72
+ data.append([identifier, text])
73
  return compute_pca(data)
74
 
75
+ inputs = []
76
+ for id_input, text_input in zip(identifier_inputs, text_inputs):
77
+ inputs.extend([id_input, text_input])
78
+
79
  analyze_button.click(fn=collect_inputs, inputs=inputs, outputs=output_plot)
80
 
81
  return demo
82
 
83
 
84
 
85
+
86
  # Launch the app
87
  text_editor_app().launch()