Spaces:
Runtime error
Runtime error
seaoctopusredchicken
commited on
Commit
•
7141fe9
1
Parent(s):
c0349f4
Cut some stuff
Browse files- README.md +2 -2
- app.py +36 -33
- receipt.webp +0 -0
- testocr.png +0 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title: Hive OCR
|
3 |
emoji: 🦀
|
4 |
colorFrom: pink
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
1 |
---
|
2 |
+
title: Hive OCR simple
|
3 |
emoji: 🦀
|
4 |
colorFrom: pink
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.14.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
app.py
CHANGED
@@ -1,40 +1,43 @@
|
|
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
from PIL import Image, ImageDraw
|
5 |
|
6 |
def infer(im):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
iface = gr.Interface(
|
33 |
fn=infer,
|
34 |
-
title="Hive OCR",
|
35 |
-
description="Demo for Hive OCR.Transcribe and analyze media depicting typed, written, or graphic text",
|
36 |
-
inputs=[gr.
|
37 |
-
outputs=[
|
38 |
-
examples=[
|
39 |
-
article=
|
40 |
-
).launch()
|
|
|
1 |
+
from codecs import encode, decode
|
2 |
import requests
|
3 |
import gradio as gr
|
4 |
+
|
|
|
5 |
|
6 |
def infer(im):
|
7 |
+
im.save("converted.png")
|
8 |
+
url = "https://ajax.thehive.ai/api/demo/classify?endpoint=text_recognition"
|
9 |
+
files = {
|
10 |
+
"image": ("converted.png", open("converted.png", "rb"), "image/png"),
|
11 |
+
"model_type": (None, "detection"),
|
12 |
+
"media_type": (None, "photo"),
|
13 |
+
}
|
14 |
+
headers = {"referer": "https://thehive.ai/"}
|
15 |
+
|
16 |
+
res = requests.post(url, headers=headers, files=files)
|
17 |
+
|
18 |
+
text = ""
|
19 |
+
blocks = []
|
20 |
+
for output in res.json()["response"]["output"]:
|
21 |
+
text += output["block_text"]
|
22 |
+
for poly in output["bounding_poly"]:
|
23 |
+
blocks.append(
|
24 |
+
{
|
25 |
+
"text": "".join([c["class"] for c in poly["classes"]]),
|
26 |
+
"rect": poly["dimensions"],
|
27 |
+
}
|
28 |
+
)
|
29 |
+
|
30 |
+
text = decode(encode(text, "latin-1", "backslashreplace"), "unicode-escape")
|
31 |
+
|
32 |
+
return text, blocks
|
33 |
+
|
34 |
|
35 |
iface = gr.Interface(
|
36 |
fn=infer,
|
37 |
+
title="Hive OCR simple",
|
38 |
+
description="Demo for Hive OCR. Transcribe and analyze media depicting typed, written, or graphic text",
|
39 |
+
inputs=[gr.Image(type="pil")],
|
40 |
+
outputs=["text", "json"],
|
41 |
+
examples=["20131216170659.jpg"],
|
42 |
+
article='<a href="https://thehive.ai/hive-ocr-solutions">Hive OCR</a>',
|
43 |
+
).launch()
|
receipt.webp
DELETED
Binary file (98.4 kB)
|
|
testocr.png
DELETED
Binary file (23.4 kB)
|
|