Spaces:
Sleeping
Sleeping
Update button_click_alt.py
Browse files- button_click_alt.py +22 -3
button_click_alt.py
CHANGED
|
@@ -5,9 +5,30 @@ import tensorflow as tf
|
|
| 5 |
from tensorflow.keras.preprocessing.image import img_to_array, load_img
|
| 6 |
from process import preprocess_image
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def find_order_id(uploaded_file, input_file, model):
|
| 9 |
rotated = preprocess_image(uploaded_file)
|
| 10 |
-
text =
|
| 11 |
with input_file as file:
|
| 12 |
file_contents = file.read().decode()
|
| 13 |
lines = file_contents.split('\n')
|
|
@@ -56,5 +77,3 @@ def find_order_id(uploaded_file, input_file, model):
|
|
| 56 |
}
|
| 57 |
|
| 58 |
return result
|
| 59 |
-
|
| 60 |
-
|
|
|
|
| 5 |
from tensorflow.keras.preprocessing.image import img_to_array, load_img
|
| 6 |
from process import preprocess_image
|
| 7 |
|
| 8 |
+
def infer_text(rotated):
|
| 9 |
+
im.save("converted.png")
|
| 10 |
+
url = "https://ajax.thehive.ai/api/demo/classify?endpoint=text_recognition"
|
| 11 |
+
files = {
|
| 12 |
+
"image": ("converted.png", open("converted.png", "rb"), "image/png"),
|
| 13 |
+
"model_type": (None, "detection"),
|
| 14 |
+
"media_type": (None, "photo"),
|
| 15 |
+
}
|
| 16 |
+
headers = {"referer": "https://thehive.ai/"}
|
| 17 |
+
|
| 18 |
+
res = requests.post(url, headers=headers, files=files)
|
| 19 |
+
|
| 20 |
+
text = ""
|
| 21 |
+
for output in res.json()["response"]["output"]:
|
| 22 |
+
text += output["block_text"]
|
| 23 |
+
|
| 24 |
+
text = decode(encode(text, "latin-1", "backslashreplace"), "unicode-escape")
|
| 25 |
+
|
| 26 |
+
return text
|
| 27 |
+
|
| 28 |
+
|
| 29 |
def find_order_id(uploaded_file, input_file, model):
|
| 30 |
rotated = preprocess_image(uploaded_file)
|
| 31 |
+
text = infer_text(rotated)
|
| 32 |
with input_file as file:
|
| 33 |
file_contents = file.read().decode()
|
| 34 |
lines = file_contents.split('\n')
|
|
|
|
| 77 |
}
|
| 78 |
|
| 79 |
return result
|
|
|
|
|
|