Spaces:
Sleeping
Sleeping
Commit
·
27e7139
1
Parent(s):
b0ba4c4
fixed output and added a copy button
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
import gradio as gr # For interface
|
3 |
from sentence_transformers import SentenceTransformer # For embedding the text
|
4 |
import torch # For gpu
|
|
|
5 |
|
6 |
# Make the app device agnostic
|
7 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
@@ -16,13 +17,19 @@ def predict(input_text):
|
|
16 |
# Calculate embeddings by calling model.encode(), specifying the device
|
17 |
embeddings = model.encode(input_text, device=device)
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Gradio app interface
|
22 |
gradio_app = gr.Interface(
|
23 |
predict,
|
24 |
-
inputs="
|
25 |
-
outputs=gr.Textbox(
|
26 |
title="Text to Vector Generator",
|
27 |
description="Input a text and get its vector representation using an embedding model (mixedbread-ai/mxbai-embed-large-v1)."
|
28 |
)
|
|
|
2 |
import gradio as gr # For interface
|
3 |
from sentence_transformers import SentenceTransformer # For embedding the text
|
4 |
import torch # For gpu
|
5 |
+
import numpy as np
|
6 |
|
7 |
# Make the app device agnostic
|
8 |
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
|
|
17 |
# Calculate embeddings by calling model.encode(), specifying the device
|
18 |
embeddings = model.encode(input_text, device=device)
|
19 |
|
20 |
+
# Set the print options to avoid truncation and use fixed-point notation
|
21 |
+
np.set_printoptions(threshold=np.inf, precision=8, suppress=True, floatmode='fixed')
|
22 |
+
|
23 |
+
# Convert the array to a string for display
|
24 |
+
embeddings_str = np.array2string(embeddings, separator=',')
|
25 |
+
|
26 |
+
return embeddings_str
|
27 |
|
28 |
# Gradio app interface
|
29 |
gradio_app = gr.Interface(
|
30 |
predict,
|
31 |
+
inputs=gr.Textbox(placeholder="Insert Text"),
|
32 |
+
outputs=gr.Textbox(show_copy_button=True, placeholder='Vector of dimensions 1024'),
|
33 |
title="Text to Vector Generator",
|
34 |
description="Input a text and get its vector representation using an embedding model (mixedbread-ai/mxbai-embed-large-v1)."
|
35 |
)
|