v2p2
Browse files
app.py
CHANGED
@@ -33,7 +33,7 @@ def generate_random_color():
|
|
33 |
|
34 |
@spaces.GPU
|
35 |
def compare_embeddings(strings):
|
36 |
-
embeddings = [get_embedding(text) for text in strings]
|
37 |
embeddings_3d = [reduce_to_3d(emb) for emb in embeddings]
|
38 |
|
39 |
fig = go.Figure()
|
@@ -53,14 +53,14 @@ def compare_embeddings(strings):
|
|
53 |
|
54 |
return fig
|
55 |
|
56 |
-
def add_string(
|
57 |
-
|
58 |
-
return
|
59 |
|
60 |
-
def remove_string(
|
61 |
-
if len(
|
62 |
-
|
63 |
-
return
|
64 |
|
65 |
with gr.Blocks(title="3D Embedding Comparison") as iface:
|
66 |
gr.Markdown("# 3D Embedding Comparison")
|
@@ -69,7 +69,9 @@ with gr.Blocks(title="3D Embedding Comparison") as iface:
|
|
69 |
with gr.Row():
|
70 |
with gr.Column(scale=1):
|
71 |
string_inputs = gr.State([""])
|
72 |
-
textboxes = gr.Textbox(label="Text 1"
|
|
|
|
|
73 |
add_button = gr.Button("Add String")
|
74 |
remove_button = gr.Button("Remove String")
|
75 |
|
@@ -78,18 +80,41 @@ with gr.Blocks(title="3D Embedding Comparison") as iface:
|
|
78 |
|
79 |
submit_button = gr.Button("Compare Embeddings")
|
80 |
|
81 |
-
def update_textboxes(
|
82 |
-
|
|
|
|
|
|
|
83 |
|
84 |
-
add_button.click(
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
submit_button.click(
|
88 |
-
|
|
|
|
|
|
|
89 |
inputs=[string_inputs],
|
90 |
outputs=[plot_output]
|
91 |
)
|
92 |
|
93 |
-
string_inputs.change(update_textboxes, inputs=[string_inputs], outputs=[textboxes])
|
94 |
-
|
95 |
iface.launch()
|
|
|
33 |
|
34 |
@spaces.GPU
|
35 |
def compare_embeddings(strings):
|
36 |
+
embeddings = [get_embedding(text) for text in strings if text.strip()]
|
37 |
embeddings_3d = [reduce_to_3d(emb) for emb in embeddings]
|
38 |
|
39 |
fig = go.Figure()
|
|
|
53 |
|
54 |
return fig
|
55 |
|
56 |
+
def add_string(string_list):
|
57 |
+
string_list.append("")
|
58 |
+
return string_list
|
59 |
|
60 |
+
def remove_string(string_list):
|
61 |
+
if len(string_list) > 1:
|
62 |
+
string_list.pop()
|
63 |
+
return string_list
|
64 |
|
65 |
with gr.Blocks(title="3D Embedding Comparison") as iface:
|
66 |
gr.Markdown("# 3D Embedding Comparison")
|
|
|
69 |
with gr.Row():
|
70 |
with gr.Column(scale=1):
|
71 |
string_inputs = gr.State([""])
|
72 |
+
textboxes = gr.Textbox.update(visible=True, label="Text 1")
|
73 |
+
with gr.Column(variant="panel") as textbox_container:
|
74 |
+
pass
|
75 |
add_button = gr.Button("Add String")
|
76 |
remove_button = gr.Button("Remove String")
|
77 |
|
|
|
80 |
|
81 |
submit_button = gr.Button("Compare Embeddings")
|
82 |
|
83 |
+
def update_textboxes(string_list):
|
84 |
+
components = []
|
85 |
+
for i, s in enumerate(string_list):
|
86 |
+
components.append(gr.Textbox(value=s, label=f"Text {i+1}"))
|
87 |
+
return gr.Column.update(visible=True, children=components)
|
88 |
|
89 |
+
add_button.click(
|
90 |
+
add_string,
|
91 |
+
inputs=[string_inputs],
|
92 |
+
outputs=[string_inputs],
|
93 |
+
then=lambda: update_textboxes(string_inputs.value)
|
94 |
+
).then(
|
95 |
+
lambda: gr.Column.update(visible=True),
|
96 |
+
None,
|
97 |
+
textbox_container
|
98 |
+
)
|
99 |
+
|
100 |
+
remove_button.click(
|
101 |
+
remove_string,
|
102 |
+
inputs=[string_inputs],
|
103 |
+
outputs=[string_inputs],
|
104 |
+
then=lambda: update_textboxes(string_inputs.value)
|
105 |
+
).then(
|
106 |
+
lambda: gr.Column.update(visible=True),
|
107 |
+
None,
|
108 |
+
textbox_container
|
109 |
+
)
|
110 |
|
111 |
submit_button.click(
|
112 |
+
lambda x: [t.strip() for t in x if t.strip()],
|
113 |
+
inputs=[string_inputs],
|
114 |
+
outputs=[string_inputs],
|
115 |
+
then=lambda x: compare_embeddings(x),
|
116 |
inputs=[string_inputs],
|
117 |
outputs=[plot_output]
|
118 |
)
|
119 |
|
|
|
|
|
120 |
iface.launch()
|