File size: 543 Bytes
19488e2
74c5a4a
be10d84
 
74c5a4a
be10d84
 
0b2ff15
 
be10d84
 
 
 
 
 
 
 
0b2ff15
 
 
be10d84
 
0b2ff15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import spaces
import gradio as gr
from transformers import AutoModel
from numpy.linalg import norm

cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))
model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-code', trust_remote_code=True)

@spaces.GPU
def generate(input1, input2):
    embeddings = model.encode(
        [
            input1,
            input2,
        ]
    )
    return str(cos_sim(embeddings[0], embeddings[1]))

gr.Interface(
    fn=generate,
    inputs=[gr.Text(), gr.Text()],
    outputs=gr.Text(),
).launch()