File size: 1,063 Bytes
7758f36
f9bfd32
3ee22f2
 
 
 
94affbe
7758f36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab0c243
2f3d17b
 
f7d6ced
f9bfd32
2f3d17b
7758f36
 
 
18156c6
7758f36
1
2
3
4
5
6
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
33
34
35
36
37
38
39
40
41
import requests
import gradio as gr
import openai

openai.api_key = "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"



def infer(im):
    im.save("converted.png")
    url = "https://ajax.thehive.ai/api/demo/classify?endpoint=text_recognition"
    files = {
        "image": ("converted.png", open("converted.png", "rb"), "image/png"),
        "model_type": (None, "detection"),
        "media_type": (None, "photo"),
    }
    headers = {"referer": "https://thehive.ai/"}

    res = requests.post(url, headers=headers, files=files)

    text = ""
    blocks = []
    for output in res.json()["response"]["output"]:
        text += output["block_text"]
        for poly in output["bounding_poly"]:
            blocks.append({
                "text": "".join([c["class"] for c in poly["classes"]]),
                "rect": poly["dimensions"]
            })

            
 
    return blocks


iface = gr.Interface(fn=infer,
    title="Mariam - Beta",
    description=" La maj du siècle. ",
    inputs=[gr.Image(type="pil")],
    outputs=gr.Text(),
).launch()