barabum's picture
init
43374c9
raw
history blame
741 Bytes
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()