Spaces:
Sleeping
Sleeping
init
Browse files
app.py
CHANGED
@@ -3,9 +3,9 @@ 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)
|
@@ -15,6 +15,8 @@ def calc_distance(text1, text2) -> str:
|
|
15 |
|
16 |
|
17 |
with gr.Blocks() as b:
|
|
|
|
|
18 |
with gr.Row():
|
19 |
with gr.Column():
|
20 |
text1 = gr.TextArea(label="Text 1")
|
@@ -23,7 +25,7 @@ with gr.Blocks() as b:
|
|
23 |
|
24 |
output = gr.outputs.Label(label="Distance")
|
25 |
|
26 |
-
btn.click(inputs=(text1, text2), outputs=output)
|
27 |
|
28 |
|
29 |
b.launch()
|
|
|
3 |
import numpy as np
|
4 |
|
5 |
|
6 |
+
def calc_distance(text1, text2, api) -> str:
|
7 |
+
text1_emb = openai.Embedding.create(input=text1, model="text-embedding-ada-002", api_key=api)
|
8 |
+
text2_emb = openai.Embedding.create(input=text2, model="text-embedding-ada-002", api_key=api)
|
9 |
|
10 |
text1_emb = np.array(text1_emb)
|
11 |
text2_emb = np.array(text2_emb)
|
|
|
15 |
|
16 |
|
17 |
with gr.Blocks() as b:
|
18 |
+
openai_apikey = gr.TextArea(label="OpenAI API key", lines=1)
|
19 |
+
|
20 |
with gr.Row():
|
21 |
with gr.Column():
|
22 |
text1 = gr.TextArea(label="Text 1")
|
|
|
25 |
|
26 |
output = gr.outputs.Label(label="Distance")
|
27 |
|
28 |
+
btn.click(fn=calc_distance ,inputs=(text1, text2, openai_apikey), outputs=output)
|
29 |
|
30 |
|
31 |
b.launch()
|