yourplugin.php 1.39 KB
Newer Older
1
2
3
4
5
<?php
/**
 * You may localized strings in your plugin
 *
 * @package    local_yourplugin
6
 * @copyright 2024 Artem Baranovskyi
7
8
9
 * @license    http://www.gnu.org/copyleft/gpl.html gnu gpl v3 or later
 */

10
11
12
$string['pluginname'] = 'New local plugin';

// Path to the Python 3 executable
13
$python_executable = '/opt/myenv/bin/python3';
14
15
16
17
18
19

// Path to the moodlemlbackend script to be executed. First we use test API api.py, then run_LR_SBERT.py
$python_script = '/var/www/html/moodle/api.py';
//$python_script = '/var/www/html/moodle/asyst/Source/Skript/german/run_LR_SBERT.py';

// Python command you want to execute
20
21
22
//$python_command = 'print("Hello, world!!!")';
// Execution the command and getting the result
//shell_exec($python_command);
23
24
25

// Formation of a command to execute
//$full_command = $python_executable . ' -c \'' . $python_command . '\'';
26
//$full_command = $python_executable . ' ' . $python_script;
27

28
29
30
// Now call the API
$api_url  = 'http://127.0.0.1:5000/api/data';
$response = file_get_contents($api_url);
31

32
33
34
35
// Output the result (assuming backend returns JSON)
if ($response !== false) {
    $data = json_decode($response, true);
    if ($data !== null) {
36
// Data processing
37
38
39
40
41
42
// Example: output results        echo "<pre>";
        print_r($data);
        echo "</pre>";
    } else {
        echo "Error on data processing from moodlemlbackend!";
    }
43
} else {
44
    echo "Execution error: result is not a string.";
45
}