0xalfroz commited on
Commit
459b055
1 Parent(s): 3bed7b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -18,17 +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() # NumPy array
22
-
23
- # Flatten the array and return as a 1D array of floats
24
- return vectors.reshape(-1).tolist()
 
 
 
25
 
26
  demo = gr.Interface(
27
  fn=text_to_vector,
28
  inputs=gr.Textbox(label="Enter JSON array", placeholder="Enter an array of sentences as a JSON string"),
29
- outputs=gr.Textbox(label="Text Vectors (flattened float array)", lines=10),
30
  title="Batch Text to Vector",
31
- description="This demo converts an array of sentences to vectors and returns them as a flattened float array."
32
  )
33
 
34
- 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().tolist() # Convert to list
22
+ return json.dumps(vectors) # Return as JSON string
23
+
24
+
25
+
26
+
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 (JSON)", lines=10),
33
  title="Batch Text to Vector",
34
+ description="This demo converts an array of sentences to vectors and returns them as a JSON array."
35
  )
36
 
37
+ demo.launch()