Add python AI script to reactJS

Viewed 34

So I'm trying to fetch a little script I just made in python, is an OCR, using tesseract module. This is

import cv2 
import pytesseract

img = cv2.imread('plot.png')

pytesseract.pytesseract.tesseract_cmd = r'C:/Users/berna/Desktop/Programming/AI_ML_DL/Projects/OCRApp_phototext/Tesseract-OCR/tesseract.exe'
print(pytesseract.image_to_string(img))

The problem is that This script need an input image, as you can see the "plot.png". I know how to connect flask server to reactJS, but how can I do this. In ReactJS, enter the image, the script take it, And pass the print value to ReactJS

1 Answers

You can use:

  const sendFile = (file) => {
  var input = document.querySelector('input[type="file"]')

    var data = new FormData()
    data.append('file', input.files[0])

    fetch('/upload', {
      method: 'POST',
      body: data
    })
  };

Now after upload just save it on /tmp and use it in your script and delete after if you want.

Related