primer commit
This commit is contained in:
commit
0ef6f9814d
52
ajax/get_tables.php
Normal file
52
ajax/get_tables.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
ini_set('display_errors', 0);
|
||||||
|
error_reporting(0);
|
||||||
|
try {
|
||||||
|
require __DIR__ . '/../config.php';
|
||||||
|
$draw = intval($_GET['draw'] ?? 0);
|
||||||
|
$start = intval($_GET['start'] ?? 0);
|
||||||
|
$len = intval($_GET['length'] ?? 10);
|
||||||
|
$s = trim($_GET['search']['value'] ?? '');
|
||||||
|
|
||||||
|
$where = '';
|
||||||
|
$params = [];
|
||||||
|
if ($s) {
|
||||||
|
$where = "WHERE name LIKE :s";
|
||||||
|
$params[':s'] = "%$s%";
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = $pdo->query("SELECT COUNT(*) FROM models")->fetchColumn();
|
||||||
|
|
||||||
|
$filtered = $total;
|
||||||
|
if ($where) {
|
||||||
|
$stmt = $pdo->prepare("SELECT COUNT(*) FROM models $where");
|
||||||
|
$stmt->execute($params);
|
||||||
|
$filtered = $stmt->fetchColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT id, name FROM models $where ORDER BY id DESC LIMIT :start, :len";
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
foreach ($params as $k => $v) {
|
||||||
|
$stmt->bindValue($k, $v);
|
||||||
|
}
|
||||||
|
$stmt->bindValue(':start', $start, PDO::PARAM_INT);
|
||||||
|
$stmt->bindValue(':len', $len, PDO::PARAM_INT);
|
||||||
|
$stmt->execute();
|
||||||
|
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'draw' => $draw,
|
||||||
|
'recordsTotal' => $total,
|
||||||
|
'recordsFiltered' => $filtered,
|
||||||
|
'data' => $data
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode([
|
||||||
|
'draw' => 0,
|
||||||
|
'recordsTotal' => 0,
|
||||||
|
'recordsFiltered' => 0,
|
||||||
|
'data' => [],
|
||||||
|
'error' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
17
config.php
Normal file
17
config.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
$host = 'localhost';
|
||||||
|
$db = 'model_registry';
|
||||||
|
$user = 'root';
|
||||||
|
$pass = 'XmRTSMQ9';
|
||||||
|
$charset = 'utf8mb4';
|
||||||
|
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
||||||
|
$options = [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
|
PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
$pdo = new PDO($dsn, $user, $pass, $options);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Error conexión BD: " . $e->getMessage());
|
||||||
|
}
|
||||||
58
list_tables.php
Normal file
58
list_tables.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<title>Listar Tablas</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="bg-light">
|
||||||
|
<div class="container py-5">
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-header bg-secondary text-white">
|
||||||
|
<h3>Modelos en la Base de Datos</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<table id="tables" class="table table-striped" style="width:100%">
|
||||||
|
<thead class="table-dark">
|
||||||
|
<tr>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Acción</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap5.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$('#tables').DataTable({
|
||||||
|
serverSide: true,
|
||||||
|
processing: true,
|
||||||
|
ajax: 'ajax/get_tables.php',
|
||||||
|
columns: [{
|
||||||
|
data: 'name',
|
||||||
|
title: 'Nombre'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: null,
|
||||||
|
orderable: false,
|
||||||
|
render: d => `<button class="btn btn-info btn-sm" onclick="alert('ID: '+d.id)">Ver</button>`
|
||||||
|
}
|
||||||
|
],
|
||||||
|
language: {
|
||||||
|
url: '//cdn.datatables.net/plug-ins/1.13.4/i18n/es-ES.json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
54
process_model.php
Normal file
54
process_model.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'config.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Recoger datos del formulario
|
||||||
|
$name = $_POST['name'] ?? '';
|
||||||
|
$version = $_POST['version'] ?? '';
|
||||||
|
$description = $_POST['description'] ?? '';
|
||||||
|
$train_date = (!empty($_POST['train_date'])) ? $_POST['train_date'] : null;
|
||||||
|
$layers = isset($_POST['layers']) && $_POST['layers'] !== '' ? intval($_POST['layers']) : null;
|
||||||
|
$model_size = isset($_POST['model_size']) && $_POST['model_size'] !== '' ? floatval($_POST['model_size']) : null;
|
||||||
|
$accuracy = isset($_POST['accuracy']) && $_POST['accuracy'] !== '' ? floatval($_POST['accuracy']) : null;
|
||||||
|
$f1_score = isset($_POST['f1_score']) && $_POST['f1_score'] !== '' ? floatval($_POST['f1_score']) : null;
|
||||||
|
$hyperparams = $_POST['hyperparams'] ?? null;
|
||||||
|
$dataset = $_POST['dataset'] ?? null;
|
||||||
|
|
||||||
|
$model_file_path = null;
|
||||||
|
$upload_dir = __DIR__ . '/uploads/';
|
||||||
|
|
||||||
|
// Subida de archivo del modelo
|
||||||
|
if (!empty($_FILES['model_file']['name'])) {
|
||||||
|
$filename = basename($_FILES['model_file']['name']);
|
||||||
|
$target_path = $upload_dir . $filename;
|
||||||
|
if (move_uploaded_file($_FILES['model_file']['tmp_name'], $target_path)) {
|
||||||
|
$model_file_path = 'uploads/' . $filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inserción en BD
|
||||||
|
$sql = "INSERT INTO models
|
||||||
|
(name, version, description, layers, model_size, model_file_path, train_date, accuracy, f1_score, hyperparams, dataset)
|
||||||
|
VALUES (?,?,?,?,?,?,?,?,?,?,?)";
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute([
|
||||||
|
$name,
|
||||||
|
$version,
|
||||||
|
$description,
|
||||||
|
$layers,
|
||||||
|
$model_size,
|
||||||
|
$model_file_path,
|
||||||
|
$train_date,
|
||||||
|
$accuracy,
|
||||||
|
$f1_score,
|
||||||
|
$hyperparams,
|
||||||
|
$dataset
|
||||||
|
]);
|
||||||
|
|
||||||
|
header('Location: register_model.php?success=1');
|
||||||
|
exit;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
header('Location: register_model.php?error=' . urlencode($e->getMessage()));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
80
register_model.php
Normal file
80
register_model.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<!-- register_model.php -->
|
||||||
|
<?php
|
||||||
|
// Mostrar mensaje de éxito o error
|
||||||
|
if (isset($_GET['success'])) {
|
||||||
|
echo '<div class="alert alert-success text-center">✅ Modelo registrado exitosamente.</div>';
|
||||||
|
} elseif (isset($_GET['error'])) {
|
||||||
|
echo '<div class="alert alert-danger text-center">❌ ' . htmlspecialchars($_GET['error']) . '</div>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Registrar Modelo IA</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="bg-light">
|
||||||
|
<div class="container py-5">
|
||||||
|
<div class="card shadow-sm">
|
||||||
|
<div class="card-header bg-primary text-white">
|
||||||
|
<h3 class="mb-0">Registrar Modelo de IA</h3>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form action="process_model.php" method="POST" enctype="multipart/form-data">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Nombre del Modelo</label>
|
||||||
|
<input type="text" name="name" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Versión</label>
|
||||||
|
<input type="text" name="version" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Descripción</label>
|
||||||
|
<textarea name="description" class="form-control" rows="2"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Cantidad de Capas</label>
|
||||||
|
<input type="number" name="layers" class="form-control" min="1">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Tamaño/Peso del Modelo (en MB)</label>
|
||||||
|
<input type="number" name="model_size" class="form-control" step="0.01">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Archivo del Modelo</label>
|
||||||
|
<input type="file" name="model_file" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Fecha de Entrenamiento</label>
|
||||||
|
<input type="date" name="train_date" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Precisión</label>
|
||||||
|
<input type="number" step="0.0001" name="accuracy" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">F1-Score</label>
|
||||||
|
<input type="number" step="0.0001" name="f1_score" class="form-control">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Hiperparámetros (JSON)</label>
|
||||||
|
<textarea name="hyperparams" class="form-control" rows="2" placeholder='{"lr":0.001,"batch_size":32}'></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Dataset Utilizado</label>
|
||||||
|
<input type="text" name="dataset" class="form-control">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-success">Registrar Modelo</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user