Sergidev commited on
Commit
569b4a2
·
verified ·
1 Parent(s): ce5f248

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -51,23 +51,22 @@ def compare_embeddings(*texts):
51
 
52
  return fig
53
 
54
- def add_textbox(textboxes):
55
- new_textbox = gr.Textbox(label=f"Text {len(textboxes) + 1}")
56
- return textboxes + [new_textbox]
57
 
58
- def remove_textbox(textboxes):
59
- if len(textboxes) > 2:
60
- return textboxes[:-1]
61
- return textboxes
62
 
63
  with gr.Blocks() as iface:
64
  gr.Markdown("# 3D Embedding Comparison")
65
  gr.Markdown("Compare the embeddings of multiple strings visualized in 3D space using Mistral 7B.")
66
 
67
- textboxes = gr.State([gr.Textbox(label="Text 1"), gr.Textbox(label="Text 2")])
68
 
69
  with gr.Column() as textbox_container:
70
- gr.components.Row(textboxes.value)
 
 
71
 
72
  with gr.Row():
73
  add_btn = gr.Button("Add String")
@@ -76,11 +75,10 @@ with gr.Blocks() as iface:
76
  plot_output = gr.Plot()
77
 
78
  submit_btn = gr.Button("Submit")
79
- clear_btn = gr.ClearButton(components=[textbox_container, plot_output], value="Clear")
80
 
81
- add_btn.click(add_textbox, inputs=[textboxes], outputs=[textboxes])
82
- remove_btn.click(remove_textbox, inputs=[textboxes], outputs=[textboxes])
83
- textboxes.change(lambda x: gr.components.Row(x), inputs=[textboxes], outputs=[textbox_container])
84
  submit_btn.click(compare_embeddings, inputs=textboxes, outputs=[plot_output])
85
 
86
  iface.launch()
 
51
 
52
  return fig
53
 
54
+ def add_textbox(num_textboxes):
55
+ return gr.Textbox.update(visible=True, label=f"Text {num_textboxes + 1}"), num_textboxes + 1
 
56
 
57
+ def remove_textbox(num_textboxes):
58
+ return gr.Textbox.update(visible=False), max(2, num_textboxes - 1)
 
 
59
 
60
  with gr.Blocks() as iface:
61
  gr.Markdown("# 3D Embedding Comparison")
62
  gr.Markdown("Compare the embeddings of multiple strings visualized in 3D space using Mistral 7B.")
63
 
64
+ num_textboxes = gr.State(value=2)
65
 
66
  with gr.Column() as textbox_container:
67
+ textboxes = [gr.Textbox(label=f"Text {i+1}") for i in range(10)] # Create 10 textboxes
68
+ for i in range(2, 10): # Hide textboxes 3-10 initially
69
+ textboxes[i].visible = False
70
 
71
  with gr.Row():
72
  add_btn = gr.Button("Add String")
 
75
  plot_output = gr.Plot()
76
 
77
  submit_btn = gr.Button("Submit")
78
+ clear_btn = gr.ClearButton(components=textboxes + [plot_output], value="Clear")
79
 
80
+ add_btn.click(add_textbox, inputs=[num_textboxes], outputs=[textboxes[-1], num_textboxes])
81
+ remove_btn.click(remove_textbox, inputs=[num_textboxes], outputs=[textboxes[-1], num_textboxes])
 
82
  submit_btn.click(compare_embeddings, inputs=textboxes, outputs=[plot_output])
83
 
84
  iface.launch()