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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -51,21 +51,22 @@ def compare_embeddings(*texts):
51
 
52
  return fig
53
 
54
- def add_textbox(textboxes):
55
- textboxes.append(gr.Textbox(label=f"Text {len(textboxes) + 1}"))
56
- return textboxes
 
57
 
58
- def remove_textbox(textboxes):
59
- if len(textboxes) > 2:
60
- textboxes.pop()
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
- with gr.Column():
68
- textboxes = gr.List([gr.Textbox(label="Text 1"), gr.Textbox(label="Text 2")])
69
 
70
  with gr.Row():
71
  add_btn = gr.Button("Add String")
@@ -74,10 +75,10 @@ with gr.Blocks() as iface:
74
  plot_output = gr.Plot()
75
 
76
  submit_btn = gr.Button("Submit")
77
- clear_btn = gr.ClearButton(components=[textboxes, plot_output], value="Clear")
78
 
79
- add_btn.click(add_textbox, inputs=[textboxes], outputs=[textboxes])
80
- remove_btn.click(remove_textbox, inputs=[textboxes], outputs=[textboxes])
81
- submit_btn.click(compare_embeddings, inputs=[textboxes], outputs=[plot_output])
82
 
83
  iface.launch()
 
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
  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()