Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,18 +7,15 @@ from sentence_transformers import SentenceTransformer
|
|
| 7 |
model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5", trust_remote_code=True)
|
| 8 |
|
| 9 |
def embed(document: str):
|
| 10 |
-
'''This will embed text and return
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
with gr.Blocks() as app:
|
| 15 |
-
# Create an input text box
|
| 16 |
text_input = gr.Textbox(label="Enter text to embed")
|
|
|
|
| 17 |
|
| 18 |
-
# Create an output component to display the embedding
|
| 19 |
-
output = gr.JSON(label="Text Embedding")
|
| 20 |
-
|
| 21 |
-
# When the input text is submitted, call the embedding function and display the output
|
| 22 |
text_input.submit(embed, inputs=text_input, outputs=output)
|
| 23 |
|
| 24 |
if __name__ == '__main__':
|
|
|
|
| 7 |
model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5", trust_remote_code=True)
|
| 8 |
|
| 9 |
def embed(document: str):
|
| 10 |
+
'''This will embed text, normalize the embedding, and return a 768-dimension vector'''
|
| 11 |
+
embedding = model.encode(document)
|
| 12 |
+
normalized_embedding = embedding / np.linalg.norm(embedding)
|
| 13 |
+
return normalized_embedding.tolist()
|
| 14 |
|
| 15 |
with gr.Blocks() as app:
|
|
|
|
| 16 |
text_input = gr.Textbox(label="Enter text to embed")
|
| 17 |
+
output = gr.JSON(label="Normalized Text Embedding")
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
text_input.submit(embed, inputs=text_input, outputs=output)
|
| 20 |
|
| 21 |
if __name__ == '__main__':
|