Spaces:
Sleeping
Sleeping
codeblacks
commited on
Commit
•
a95d821
1
Parent(s):
1bab135
Update app.py
Browse files
app.py
CHANGED
@@ -5,15 +5,24 @@ from sentence_transformers import SentenceTransformer
|
|
5 |
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
6 |
|
7 |
def get_embeddings(sentences):
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
return str(embeddings.tolist())
|
10 |
|
11 |
# Define the Gradio interface
|
12 |
interface = gr.Interface(
|
13 |
fn=get_embeddings, # Function to call
|
14 |
-
inputs=gr.Textbox(lines=
|
15 |
-
|
16 |
-
outputs=gr.Textbox(label="Embeddings"),
|
17 |
title="Sentence Embeddings", # Interface title
|
18 |
description="Enter sentences to get their embeddings." # Description
|
19 |
)
|
|
|
5 |
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
6 |
|
7 |
def get_embeddings(sentences):
|
8 |
+
# Check if the input is a list
|
9 |
+
if isinstance(sentences, list):
|
10 |
+
sentence_list = sentences
|
11 |
+
elif isinstance(sentences, str):
|
12 |
+
# If it's a string, split by new lines to create a list of sentences
|
13 |
+
sentence_list = sentences.split("\n")
|
14 |
+
else:
|
15 |
+
raise ValueError("Input should be either a string or a list of strings.")
|
16 |
+
|
17 |
+
# Generate embeddings
|
18 |
+
embeddings = model.encode(sentence_list, convert_to_tensor=True)
|
19 |
return str(embeddings.tolist())
|
20 |
|
21 |
# Define the Gradio interface
|
22 |
interface = gr.Interface(
|
23 |
fn=get_embeddings, # Function to call
|
24 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter sentences here, one per line"), # Input component
|
25 |
+
outputs=gr.Textbox(label="Embeddings"), # Output component
|
|
|
26 |
title="Sentence Embeddings", # Interface title
|
27 |
description="Enter sentences to get their embeddings." # Description
|
28 |
)
|