Update app.py
Browse files
app.py
CHANGED
@@ -7,19 +7,23 @@ model_name = "sentence-transformers/all-mpnet-base-v2"
|
|
7 |
model = AutoModel.from_pretrained(model_name)
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
|
10 |
-
def text_to_vector(
|
11 |
-
|
|
|
12 |
outputs = model(**inputs)
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
17 |
demo = gr.Interface(
|
18 |
fn=text_to_vector,
|
19 |
-
inputs=gr.Textbox(label="Enter text"),
|
20 |
-
outputs=gr.Textbox(label="Text
|
21 |
-
title="Text to Vector",
|
22 |
-
description="This demo
|
23 |
)
|
24 |
|
25 |
demo.launch()
|
|
|
|
7 |
model = AutoModel.from_pretrained(model_name)
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
|
10 |
+
def text_to_vector(texts):
|
11 |
+
# Tokenize and process a batch of inputs
|
12 |
+
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True)
|
13 |
outputs = model(**inputs)
|
14 |
+
vectors = outputs.pooler_output.detach().numpy()
|
15 |
+
|
16 |
+
# Convert each vector to a string representation
|
17 |
+
vector_strings = [", ".join(map(str, vector)) for vector in vectors]
|
18 |
+
return vector_strings
|
19 |
|
20 |
demo = gr.Interface(
|
21 |
fn=text_to_vector,
|
22 |
+
inputs=gr.Textbox(label="Enter text", lines=4, placeholder="Enter one or more texts (separate with new lines)"),
|
23 |
+
outputs=gr.Textbox(label="Text Vectors", lines=10),
|
24 |
+
title="Batch Text to Vector",
|
25 |
+
description="This demo converts a batch of texts to vectors."
|
26 |
)
|
27 |
|
28 |
demo.launch()
|
29 |
+
|