diff --git a/public/cgi-bin/api.cgi b/public/cgi-bin/api.cgi new file mode 100755 index 0000000..52dc47e --- /dev/null +++ b/public/cgi-bin/api.cgi @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import cgi +import os +import subprocess +UPLOAD_DIR = './uploads/' + +def main(): + print("Content-Type: application/json\n") + + form = cgi.FieldStorage() + + fileitem = form['file'] + + if fileitem.filename: + fn = os.path.basename(fileitem.filename) + file_path = os.path.join(UPLOAD_DIR, fn) + open(file_path, 'wb').write(fileitem.file.read()) + result = run_ocr_script(file_path) + print(result) + os.remove(file_path) + else: + print("No file was uploaded.") + +def run_ocr_script(file_path): + try: + completed_process = subprocess.run(['./ocr.sh', file_path], check=True, text=True, capture_output=True) + return completed_process.stdout + except subprocess.CalledProcessError as e: + return f"An error occurred: {e}" + except Exception as e: + return f"Unexpected error: {e}" + +if __name__ == '__main__': + main() diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..7251f4e --- /dev/null +++ b/public/index.html @@ -0,0 +1,59 @@ + + + + Recipt OCR API + + + +

Upload Recipt

+
+ + + +
+ + +