Spaces:
Sleeping
Sleeping
init
Browse files- .gitignore +1 -0
- 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()
|