Run a python script using requirements with browser JavaScript

My main goal here is to execute a python script I have written when I run a function triggered through HTML. Here is how I have things currently set up:

I have a JavaScript File containing python run functions:

const PythonShell = require('python-shell').PythonShell;
class AHK {
   static async runScript() {
     PythonShell.run('/ahk/script.py', null, function (err) {
       if (err) throw err;
       console.log('finished');
   });
}
module.exports = AHK;

I have my main.js file which would be the js code for the HTML to handle. I’d like for it to take in the module AHK. Something simple like this:

const AHK = require('./ahk');

function runFunction(x){
 if(x = 1)
    AHK.runScript()
 }

And then I have some HTML with a javascript tag

<script type="text/javascript">
let x =1; //this is just to show x is getting populated. In the actual code it's constantly changing values

async function predict() {
  if(x > 1)
    runFunction(x)
}
</script>

Biggest issue I’m facing:

I’ve become aware that browser javascript doesn’t like requirements/modules. For example, the main.js file doesn’t like having a requirement at the top. I’ve tried using things like requirejs, but I can’t seem to figure out how to make something like this work. I basically need it so that when the requirement is met and the function runFunction is run, the python script is executed on my machine.

Important to note that this is all running for a personal project on my computer, so it will never not be local.