barabum commited on
Commit
43374c9
1 Parent(s): bc0f2f7
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +29 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ /venv/
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import numpy as np
4
+
5
+
6
+ def calc_distance(text1, text2) -> str:
7
+ text1_emb = openai.Embedding.create(input=text1, model="text-embedding-ada-002")
8
+ text2_emb = openai.Embedding.create(input=text2, model="text-embedding-ada-002")
9
+
10
+ text1_emb = np.array(text1_emb)
11
+ text2_emb = np.array(text2_emb)
12
+
13
+ distance = np.linalg.norm(text1_emb-text2_emb)
14
+ return str(distance)
15
+
16
+
17
+ with gr.Blocks() as b:
18
+ with gr.Row():
19
+ with gr.Column():
20
+ text1 = gr.TextArea(label="Text 1")
21
+ text2 = gr.TextArea(label="Text 2")
22
+ btn = gr.Button("Calculate")
23
+
24
+ output = gr.outputs.Label(label="Distance")
25
+
26
+ btn.click(inputs=(text1, text2), outputs=output)
27
+
28
+
29
+ b.launch()