Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ def reduce_to_3d(embedding):
|
|
30 |
|
31 |
@spaces.GPU
|
32 |
def compare_embeddings(*texts):
|
33 |
-
embeddings = [get_embedding(text) for text in texts]
|
34 |
embeddings_3d = [reduce_to_3d(emb) for emb in embeddings]
|
35 |
|
36 |
fig = go.Figure()
|
@@ -51,7 +51,7 @@ def compare_embeddings(*texts):
|
|
51 |
|
52 |
return fig
|
53 |
|
54 |
-
def
|
55 |
with gr.Blocks() as new_interface:
|
56 |
text_inputs = [gr.Textbox(label=f"Text {i+1}") for i in range(num_inputs)]
|
57 |
output = gr.Plot()
|
@@ -64,8 +64,14 @@ with gr.Blocks() as iface:
|
|
64 |
gr.Markdown("Compare the embeddings of multiple strings visualized in 3D space using Mistral 7B.")
|
65 |
|
66 |
num_inputs = gr.Slider(minimum=2, maximum=10, step=1, value=2, label="Number of texts to compare")
|
67 |
-
|
68 |
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
iface.launch()
|
|
|
30 |
|
31 |
@spaces.GPU
|
32 |
def compare_embeddings(*texts):
|
33 |
+
embeddings = [get_embedding(text) for text in texts if text.strip()] # Only process non-empty texts
|
34 |
embeddings_3d = [reduce_to_3d(emb) for emb in embeddings]
|
35 |
|
36 |
fig = go.Figure()
|
|
|
51 |
|
52 |
return fig
|
53 |
|
54 |
+
def create_interface(num_inputs):
|
55 |
with gr.Blocks() as new_interface:
|
56 |
text_inputs = [gr.Textbox(label=f"Text {i+1}") for i in range(num_inputs)]
|
57 |
output = gr.Plot()
|
|
|
64 |
gr.Markdown("Compare the embeddings of multiple strings visualized in 3D space using Mistral 7B.")
|
65 |
|
66 |
num_inputs = gr.Slider(minimum=2, maximum=10, step=1, value=2, label="Number of texts to compare")
|
67 |
+
interface_container = gr.HTML()
|
68 |
|
69 |
+
def update_interface(num):
|
70 |
+
return create_interface(num)
|
71 |
+
|
72 |
+
num_inputs.change(fn=update_interface, inputs=[num_inputs], outputs=[interface_container])
|
73 |
+
|
74 |
+
# Initialize the interface with 2 text boxes
|
75 |
+
interface_container.update(create_interface(2))
|
76 |
|
77 |
iface.launch()
|