added web api and web ui
This commit is contained in:
parent
0f58bbc330
commit
4b196c578f
35
public/cgi-bin/api.cgi
Executable file
35
public/cgi-bin/api.cgi
Executable file
@ -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()
|
59
public/index.html
Normal file
59
public/index.html
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Recipt OCR API</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background-color: #f4f4f9;
|
||||||
|
color: #333;
|
||||||
|
margin: 40px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 90vh;
|
||||||
|
}
|
||||||
|
form {
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
color: #5d5d5d;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
display: block;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
input[type="file"] {
|
||||||
|
display: block;
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
input[type="submit"] {
|
||||||
|
background-color: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
input[type="submit"]:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Upload Recipt</h1>
|
||||||
|
<form action="/cgi-bin/api.cgi" method="post" enctype="multipart/form-data">
|
||||||
|
<label for="file">Select an image (PNG or JPEG):</label>
|
||||||
|
<input type="file" name="file" id="file" accept=".png, .jpeg, .jpg">
|
||||||
|
<input type="submit" value="Upload">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user