Youssouf Traore commited on
Commit
7758f36
·
1 Parent(s): 7298842

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -19
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
- def extract_text(image):
9
- image = Image.open(image.name)
10
- image = image.convert('L')
11
- image = np.array(image)
12
- text = pytesseract.image_to_string(image)
13
- print(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  return text
15
 
16
- # Définir l'interface utilisateur
17
- inputs = gr.Image(label='Upload an image',image_mode='L',tool='select',type='pil')
18
- outputs = gr.outputs.Textbox()
19
- interface = gr.Interface(fn=extract_text, inputs=inputs, outputs=outputs,
20
- title="Extraction de texte à partir d'une image",
21
- description="Téléchargez une image contenant du texte et cliquez sur 'Predict' pour extraire le texte.")
22
-
23
- interface.launch()
 
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()