Update app.py
Browse files
app.py
CHANGED
@@ -33,7 +33,7 @@ def generate_random_color():
|
|
33 |
|
34 |
@spaces.GPU
|
35 |
def compare_embeddings(*texts):
|
36 |
-
embeddings = [get_embedding(text) for text in texts]
|
37 |
embeddings_3d = [reduce_to_3d(emb) for emb in embeddings]
|
38 |
|
39 |
fig = go.Figure()
|
@@ -61,7 +61,8 @@ class DynamicInterface:
|
|
61 |
gr.Markdown("# 3D Embedding Comparison")
|
62 |
gr.Markdown("Compare the embeddings of strings visualized in 3D space using Mistral 7B.")
|
63 |
|
64 |
-
|
|
|
65 |
|
66 |
with gr.Row():
|
67 |
add_btn = gr.Button("Add String")
|
@@ -73,30 +74,28 @@ class DynamicInterface:
|
|
73 |
|
74 |
output = gr.Plot()
|
75 |
|
76 |
-
add_btn.click(self.add_string,
|
77 |
-
remove_btn.click(self.remove_string,
|
78 |
-
clear_btn.click(self.clear_inputs,
|
79 |
submit_btn.click(compare_embeddings, inputs=self.string_boxes, outputs=output)
|
80 |
|
81 |
return interface
|
82 |
|
83 |
def add_string(self):
|
84 |
self.num_strings += 1
|
85 |
-
|
86 |
-
|
|
|
87 |
|
88 |
def remove_string(self):
|
89 |
if self.num_strings > 2:
|
90 |
self.num_strings -= 1
|
91 |
self.string_boxes.pop()
|
92 |
-
return self.
|
93 |
-
return
|
94 |
|
95 |
-
def clear_inputs(self
|
96 |
-
return ["" for _ in
|
97 |
-
|
98 |
-
def rebuild_interface(self):
|
99 |
-
return gr.update(visible=False), self.build_interface()
|
100 |
|
101 |
def launch(self):
|
102 |
self.interface.launch()
|
|
|
33 |
|
34 |
@spaces.GPU
|
35 |
def compare_embeddings(*texts):
|
36 |
+
embeddings = [get_embedding(text) for text in texts if text.strip()]
|
37 |
embeddings_3d = [reduce_to_3d(emb) for emb in embeddings]
|
38 |
|
39 |
fig = go.Figure()
|
|
|
61 |
gr.Markdown("# 3D Embedding Comparison")
|
62 |
gr.Markdown("Compare the embeddings of strings visualized in 3D space using Mistral 7B.")
|
63 |
|
64 |
+
with gr.Column() as self.string_column:
|
65 |
+
self.string_boxes = [gr.Textbox(label=f"Text {i+1}") for i in range(self.num_strings)]
|
66 |
|
67 |
with gr.Row():
|
68 |
add_btn = gr.Button("Add String")
|
|
|
74 |
|
75 |
output = gr.Plot()
|
76 |
|
77 |
+
add_btn.click(self.add_string, outputs=[self.string_column])
|
78 |
+
remove_btn.click(self.remove_string, outputs=[self.string_column])
|
79 |
+
clear_btn.click(self.clear_inputs, outputs=self.string_boxes)
|
80 |
submit_btn.click(compare_embeddings, inputs=self.string_boxes, outputs=output)
|
81 |
|
82 |
return interface
|
83 |
|
84 |
def add_string(self):
|
85 |
self.num_strings += 1
|
86 |
+
new_textbox = gr.Textbox(label=f"Text {self.num_strings}")
|
87 |
+
self.string_boxes.append(new_textbox)
|
88 |
+
return gr.Column.update(visible=True, children=self.string_boxes)
|
89 |
|
90 |
def remove_string(self):
|
91 |
if self.num_strings > 2:
|
92 |
self.num_strings -= 1
|
93 |
self.string_boxes.pop()
|
94 |
+
return gr.Column.update(visible=True, children=self.string_boxes)
|
95 |
+
return gr.Column.update()
|
96 |
|
97 |
+
def clear_inputs(self):
|
98 |
+
return ["" for _ in self.string_boxes]
|
|
|
|
|
|
|
99 |
|
100 |
def launch(self):
|
101 |
self.interface.launch()
|