How do I output the results of a Python file that’s in the same directory as my HTML, CSS and JS files

So I have a file called algo.py that takes user input, processes it through OpenAI and then outputs GPT’s response back to the user. In the HTML file, I have a form that allows the user to input their question and a section (div) where the output is displayed back to the user. I’ve tried using node JS to capture the user data and then relay that to the algo.py but to no avail. Below are snippets of my code from the HTML and python code. I’m open to suggestions and would appreciate any modifications to my current code with comments so I can understand your line of reasoning.

HTML form:

            <!-- SEARCH FORM  -->
            <form id="searchform" onsubmit="submitForm(event)">
                <div class="search">
                    <span class="search-icon material-symbols-outlined">search</span>
                    <input id="searchinput" class="search-input" type="search" placeholder="What did you want to build? ">
                    <button type="submit">Generate</button>
                </div>
            </form>

Script in same HTML file:

<script>
    function submitForm(event) {
        // prevent default form submission
        event.preventDefault();
        
        // Capture user input
        var userInput = document.getElementById("searchinput").value;
        
        // Send user input over to execute python script locally
        fetch('/execute_script', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ prompt: userInput }),
        })
        .then(response => {
            if (!response.ok) {
                throw new Error('Server response was not OK')
            }
            return response.json();
        })

        .then(data => {
            // Display response from the Python script
            var responseContainer = document.getElementById("responseContainer");
            responseContainer.innerHTML = "<p>" + data.response + "</p>";

        })
        .catch(error => {
            console.error('Error:', error);
        });
    }
</script>

Python script:

import subprocess
import sys
import json
import cgi

def install(library):
    subprocess.check_call([sys.executable, "-m", "pip", "install", library])

install('openai')

import openai
from openai import OpenAI

# Set up OpenAI API key
openai.api_key = '...'


client = OpenAI(
    # This is the default and can be omitted
    api_key='...',
)

def  AI_PC_Buddy(prompt):
    messages = [{'role': 'user', 'content': prompt}]
    
    response = client.chat.completions.create(
        model='gpt-3.5-turbo',
        messages=messages
    )
    return response.choices[0].message.content.strip()

# Process CGI input and output
form = cgi.FieldStorage()
prompt = form.getValue('prompt', '')

response = AI_PC_Buddy(prompt)

print("Content-type: application/jsonn")
print(json.dumps({'response': response}))

Node server.js:

const express = require('express');
const bodyParser = require('body-parser');
const { exec } = require('child_process');

const app = express();
const port = 8005;

// Parse URL-encoded bodies (as sent by HTML forms)
app.use(express.urlencoded());

// Parse JSON bodies (as sent by API clients)
app.use(express.json());

// Define the route for handling POST requests to /execute_script
app.post('/execute_script', (req, res) => {
    const userInput = req.body.prompt;
    
    // Execute the Python script with the user input as a command-line argument
    exec(`python3 algo.py "${userInput}"`, (error, stdout, stderr) => {
        if (error) {
            console.error(`Error executing Python script: ${error.message}`);
            return;
        }
        if (stderr) {
            console.error(`Python script encountered an error: ${stderr}`);
            return;
        }
        // Send the output of the Python script back to the client
        res.send(stdout);
    });
});

// Start the server
app.listen(port, () => {
    console.log(`Server is running on http://localhost:${port}`);
});