25 lines
826 B
PHP
25 lines
826 B
PHP
<?php
|
|
// Include the configuration file
|
|
require_once 'config.php';
|
|
|
|
// Check if a POST request is sent
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
$conversation = $input['conversation'];
|
|
|
|
// Prepare the command to execute the Python script
|
|
$command = escapeshellcmd("python3 assistant.py '" . json_encode($conversation) . "'");
|
|
$output = shell_exec($command);
|
|
|
|
// Decode the response from Python script
|
|
$response = json_decode($output, true);
|
|
|
|
// Send back the response
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['response' => $response['response']]);
|
|
} else {
|
|
// If not a POST request, return an error
|
|
header('HTTP/1.1 405 Method Not Allowed');
|
|
echo 'Only POST requests are allowed.';
|
|
}
|
|
?>
|