Youssouf Traore
commited on
Commit
·
7758f36
1
Parent(s):
7298842
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,36 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import pytesseract
|
3 |
-
import cv2
|
4 |
-
import numpy as np
|
5 |
-
from PIL import Image
|
6 |
-
from io import BytesIO
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
return text
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
1 |
+
import requests
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
|
5 |
+
def infer(im):
|
6 |
+
im.save("converted.png")
|
7 |
+
url = "https://ajax.thehive.ai/api/demo/classify?endpoint=text_recognition"
|
8 |
+
files = {
|
9 |
+
"image": ("converted.png", open("converted.png", "rb"), "image/png"),
|
10 |
+
"model_type": (None, "detection"),
|
11 |
+
"media_type": (None, "photo"),
|
12 |
+
}
|
13 |
+
headers = {"referer": "https://thehive.ai/"}
|
14 |
+
|
15 |
+
res = requests.post(url, headers=headers, files=files)
|
16 |
+
|
17 |
+
text = ""
|
18 |
+
blocks = []
|
19 |
+
for output in res.json()["response"]["output"]:
|
20 |
+
text += output["block_text"]
|
21 |
+
for poly in output["bounding_poly"]:
|
22 |
+
blocks.append({
|
23 |
+
"text": "".join([c["class"] for c in poly["classes"]]),
|
24 |
+
"rect": poly["dimensions"]
|
25 |
+
})
|
26 |
+
|
27 |
return text
|
28 |
|
29 |
+
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=infer,
|
32 |
+
title="Mariam - Beta",
|
33 |
+
description=" La maj du siècle. ",
|
34 |
+
inputs=[gr.Image(type="pil")],
|
35 |
+
outputs=["text"],
|
36 |
+
).launch()
|