initial commit
This commit is contained in:
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Run
|
||||||
|
```bash
|
||||||
|
python app.py
|
||||||
|
```
|
||||||
|
|
||||||
|
# Open
|
||||||
|
[http://localhost:8501](http://localhost:8501)
|
||||||
13
app.py
Normal file
13
app.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# http://localhost:8501
|
||||||
|
try: import os, io, tempfile, streamlit
|
||||||
|
except: os.system('pip install -q streamlit')
|
||||||
|
finally: import streamlit as st
|
||||||
|
if st.runtime.exists():
|
||||||
|
st.title('맥모닝 OCR')
|
||||||
|
if img := st.file_uploader("Choose a file"):
|
||||||
|
st.image(io.BytesIO(blob := img.getvalue()))
|
||||||
|
with tempfile.TemporaryDirectory() as tmp, \
|
||||||
|
open(path := f'{tmp}/{img.name}', 'wb') as f:
|
||||||
|
f.write(blob)
|
||||||
|
st.code(os.popen(f'osascript ocr.applescript {path}').read())
|
||||||
|
else: os.system('streamlit run app.py --browser.gatherUsageStats false')
|
||||||
34
ocr.applescript
Normal file
34
ocr.applescript
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
-- Credit: https://stackoverflow.com/a/75779406
|
||||||
|
|
||||||
|
use framework "Vision"
|
||||||
|
|
||||||
|
on run(argv)
|
||||||
|
set ap to current application
|
||||||
|
|
||||||
|
-- Read image content
|
||||||
|
set img to ap's NSImage's alloc()'s initWithContentsOfFile:item 1 of argv
|
||||||
|
|
||||||
|
-- Set up request handler using image's raw data
|
||||||
|
set handle to ap's VNImageRequestHandler's alloc()'s <EFBFBD>
|
||||||
|
initWithData:(img's TIFFRepresentation()) <EFBFBD>
|
||||||
|
options:(ap's NSDictionary's dictionary())
|
||||||
|
|
||||||
|
-- Initialize text request
|
||||||
|
set request to ap's VNRecognizeTextRequest's alloc()'s init()
|
||||||
|
|
||||||
|
-- Set recognition level to accurate
|
||||||
|
request's setRecognitionLevel:(ap's VNRequestTextRecognitionLevelAccurate)
|
||||||
|
|
||||||
|
-- Set recognition language to Korean
|
||||||
|
request's setRecognitionLanguages:(ap's NSArray's arrayWithObject:"ko-KR")
|
||||||
|
|
||||||
|
-- Perform the request and get the results
|
||||||
|
handle's performRequests:{request} |error|:(missing value)
|
||||||
|
|
||||||
|
-- Obtain and return the string values of the results
|
||||||
|
set res to ""
|
||||||
|
repeat with ocr in request's results()
|
||||||
|
set res to res & ((first item in (ocr's topCandidates:1))'s |string|()) & linefeed
|
||||||
|
end repeat
|
||||||
|
return res
|
||||||
|
end run
|
||||||
Reference in New Issue
Block a user