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

Update app.py

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