Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,6 +104,16 @@ def compute_embeddings(selected_task, input_text):
|
|
| 104 |
clear_cuda_cache()
|
| 105 |
return embeddings_list
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
@spaces.GPU
|
| 108 |
def compute_similarity(selected_task, sentence1, sentence2, extra_sentence1, extra_sentence2):
|
| 109 |
try:
|
|
@@ -280,6 +290,17 @@ def app_interface():
|
|
| 280 |
outputs=output_display_connector
|
| 281 |
)
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
with gr.Row():
|
| 284 |
with gr.Column():
|
| 285 |
input_text_box
|
|
|
|
| 104 |
clear_cuda_cache()
|
| 105 |
return embeddings_list
|
| 106 |
|
| 107 |
+
@spaces.GPU
|
| 108 |
+
def decode_embedding(embedding_str):
|
| 109 |
+
try:
|
| 110 |
+
embedding = [float(num) for num in embedding_str.split(',')]
|
| 111 |
+
embedding_tensor = torch.tensor(embedding, dtype=torch.float16, device=device)
|
| 112 |
+
decoded_embedding = tokenizer.decode(embedding_tensor[0], skip_special_tokens=True)
|
| 113 |
+
return decoded_embedding.cpu().numpy().tolist()
|
| 114 |
+
except Exception as e:
|
| 115 |
+
return f"Error in decoding: {str(e)}"
|
| 116 |
+
|
| 117 |
@spaces.GPU
|
| 118 |
def compute_similarity(selected_task, sentence1, sentence2, extra_sentence1, extra_sentence2):
|
| 119 |
try:
|
|
|
|
| 290 |
outputs=output_display_connector
|
| 291 |
)
|
| 292 |
|
| 293 |
+
with gr.Tab("Decode Embedding"):
|
| 294 |
+
embedding_input = gr.Textbox(label="Enter Embedding (comma-separated floats)")
|
| 295 |
+
decode_button = gr.Button("Decode")
|
| 296 |
+
decoded_output = gr.Textbox(label="Decoded Embedding")
|
| 297 |
+
|
| 298 |
+
decode_button.click(
|
| 299 |
+
fn=decode_embedding,
|
| 300 |
+
inputs=embedding_input,
|
| 301 |
+
outputs=decoded_output
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
with gr.Row():
|
| 305 |
with gr.Column():
|
| 306 |
input_text_box
|