Update app.py
Browse files
app.py
CHANGED
|
@@ -18,15 +18,20 @@ def text_to_vector(texts_json):
|
|
| 18 |
|
| 19 |
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True)
|
| 20 |
outputs = model(**inputs)
|
| 21 |
-
vectors = outputs.pooler_output.detach().numpy()
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=text_to_vector,
|
| 26 |
inputs=gr.Textbox(label="Enter JSON array", placeholder="Enter an array of sentences as a JSON string"),
|
| 27 |
-
outputs=gr.Textbox(label="Text Vectors (
|
| 28 |
title="Batch Text to Vector",
|
| 29 |
-
description="This demo converts an array of sentences to vectors and returns them as a
|
| 30 |
)
|
| 31 |
|
| 32 |
-
demo.launch()
|
|
|
|
| 18 |
|
| 19 |
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True)
|
| 20 |
outputs = model(**inputs)
|
| 21 |
+
vectors = outputs.pooler_output.detach().numpy()
|
| 22 |
+
|
| 23 |
+
# Convert to PostgreSQL-friendly array format
|
| 24 |
+
postgres_array = "{" + ",".join(["{" + ",".join(map(str, v)) + "}" for v in vectors]) + "}"
|
| 25 |
+
|
| 26 |
+
return postgres_array
|
| 27 |
+
|
| 28 |
|
| 29 |
demo = gr.Interface(
|
| 30 |
fn=text_to_vector,
|
| 31 |
inputs=gr.Textbox(label="Enter JSON array", placeholder="Enter an array of sentences as a JSON string"),
|
| 32 |
+
outputs=gr.Textbox(label="Text Vectors (PostgreSQL Array)", lines=10),
|
| 33 |
title="Batch Text to Vector",
|
| 34 |
+
description="This demo converts an array of sentences to vectors and returns them as a PostgreSQL-friendly array."
|
| 35 |
)
|
| 36 |
|
| 37 |
+
demo.launch()
|