0xalfroz commited on
Commit
23b27f7
1 Parent(s): 4ebac2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
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().tolist() # Convert to list
22
- return json.dumps(vectors) # Return as JSON string
 
 
 
 
 
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 (JSON)", lines=10),
28
  title="Batch Text to Vector",
29
- description="This demo converts an array of sentences to vectors and returns them as a JSON array."
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()