PHP Classes

File: salvar_vetor.php

Recommend this page to a friend!
  Packages of Rodrigo Faustino   Embeddings Space   salvar_vetor.php   Download  
File: salvar_vetor.php
Role: Application script
Content type: text/plain
Description: Application script
Class: Embeddings Space
Generate and view semantic embeddings
Author: By
Last change:
Date: 2 months ago
Size: 748 bytes
 

Contents

Class file image Download
<?php
header
('Content-Type: application/json');

$input = json_decode(file_get_contents('php://input'), true);
if (!
$input) {
    echo
json_encode(["status" => "erro", "msg" => "Dados inválidos"]);
    exit;
}

$textoOriginal = $input['conteudo'];
$vetor = $input['vetor'];

if (
count($vetor) !== 384) {
    echo
json_encode(["status" => "erro", "msg" => "Dimensão do vetor incorreta"]);
    exit;
}

$registro = [
   
'id' => uniqid(),
   
'texto' => $textoOriginal,
   
'vetor' => $vetor
];

file_put_contents('banco_vetores.json', json_encode($registro) . "\n", FILE_APPEND);

echo
json_encode([
   
"status" => "sucesso",
   
"msg" => "Vetor de 384 dimensões recebido e armazenado.",
   
"amostra_vetor" => array_slice($vetor, 0, 5)
]);
?>