File size: 811 Bytes
a7eec35
 
 
 
ee11ba5
a7eec35
 
c5e1777
a7eec35
7be8da7
5cc24e6
 
 
 
a7eec35
 
 
5cc24e6
a7eec35
 
 
 
da46074
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import List

import gradio as gr
import spaces
import numpy as np
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("nomic-ai/nomic-embed-text-v1.5", trust_remote_code=True)

def embed(document: str):
    '''This will embed text, normalize the embedding, and return a 768-dimension vector'''
    embedding = model.encode(document)
    normalized_embedding = embedding / np.linalg.norm(embedding)
    return normalized_embedding.tolist()

with gr.Blocks() as app:
    text_input = gr.Textbox(label="Enter text to embed")
    output = gr.JSON(label="Normalized Text Embedding")

    text_input.submit(embed, inputs=text_input, outputs=output)

if __name__ == '__main__':
    app.queue().launch(server_name="0.0.0.0", show_error=True, server_port=7860, mcp_server=True)