Spaces:
Sleeping
Sleeping
File size: 741 Bytes
43374c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import gradio as gr
import openai
import numpy as np
def calc_distance(text1, text2) -> str:
text1_emb = openai.Embedding.create(input=text1, model="text-embedding-ada-002")
text2_emb = openai.Embedding.create(input=text2, model="text-embedding-ada-002")
text1_emb = np.array(text1_emb)
text2_emb = np.array(text2_emb)
distance = np.linalg.norm(text1_emb-text2_emb)
return str(distance)
with gr.Blocks() as b:
with gr.Row():
with gr.Column():
text1 = gr.TextArea(label="Text 1")
text2 = gr.TextArea(label="Text 2")
btn = gr.Button("Calculate")
output = gr.outputs.Label(label="Distance")
btn.click(inputs=(text1, text2), outputs=output)
b.launch() |