composer require symfony/process
-----------------analyse_string.py---------------------
# analyse_string.py
#!/usr/bin/python

import sys
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

analyser = SentimentIntensityAnalyzer()
print(str(analyser.polarity_scores(sys.argv[1])))
-------------------------- Laravel Code---------------------------
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

$text = 'The text you are desperate to analyze :)";
$process = new Process("python3 /Path/To/analyse_string.py \"{$text}\"");
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}

echo $process->getOutput();
// Result (string): {'neg': 0.204, 'neu': 0.531, 'pos': 0.265, 'compound': 0.1779}
You can also pass array to python using json string
$process = new Process("python3 /Path/To/analyse_json.py {$json}");
and inside python retrieve it like this
x=sys.argv[1]
data=json.loads(x)

for item in data:
    #do whatever u want
by გიორგი უზნაძე
3 years ago
Laravel
0
Pro tip: use ```triple backticks around text``` to write in code fences