<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $ulasan = $_POST['ulasan'];

    $python = 'C:\Users\Farhan\AppData\Local\Programs\Python\Python313\\python.exe';

    $command = escapeshellcmd("$python model_predict.py " . escapeshellarg($ulasan));
    $output = shell_exec($command);

    if ($output === null || trim($output) === "") {
        echo "Gagal menjalankan model. Coba jalankan manual di CMD:<br><code>$command</code>";
        exit;
    }

    header("Location: deteksi_sentimen.php?hasil=" . urlencode(trim($output)) . "&ulasan=" . urlencode($ulasan));
    exit;
}
?>