How to build a chrome extension that runs a python script?

Viewed 4008

I'm building a chrome extension written in javascript and I want to run a python script in it. When the user clicks a button, the python script will run.

My python code is shown below:

h = html2text.HTML2Text()
h.ignore_links = True

categories = ['python', 'javascript', 'java', 'c', 'r', 'while_loop', 'for_loop']

#Get new text data
text_list = []
text = input("Enter text: ")
# text = [' this is a text']
text = cleanPunc(text.lower())
text = stemming(text)

text_list.append(text)

vectorizer = pickle.load(open('vectorizer.sav', 'rb'))
x_text = vectorizer.transform(text_list)

predicted_tags = []
for category in categories:
    print('... Processing {}'.format(category))

    #load model
    filename = 'svc-' + category + '.sav'
    loaded_model = pickle.load(open(filename, 'rb'))
    result = loaded_model.predict(x_text)
    print(result)

    if result[0] == 1:
        predicted_tags.append(category)
print(predicted_tags)

I have read about native messaging but i don't understand how to use it. It says there that I need to create a host.py but I don't understand why the need to create one. Please give me a simple example of a chrome extension that uses a python script in it. I need some reference to make my own. Please, please. Don't delete this question @ stack overflow people.

0 Answers
Related