26 lines
891 B
PHP
26 lines
891 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);
|
|
$user_message = $input['message'];
|
|
|
|
// Prepare the command to execute the Python script
|
|
// Note: Make sure `python` or `python3` is properly configured in your system's PATH.
|
|
$command = escapeshellcmd("python3 assistant.py '$user_message'");
|
|
$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.';
|
|
}
|
|
?>
|