File size: 949 Bytes
f9bfd32
03a1418
 
94affbe
03a1418
94affbe
 
 
 
 
 
 
 
 
f9bfd32
 
03a1418
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
import pytesseract
from PIL import Image
import cv2
def extract_text(image):

    img_cv = cv2.imread(image)
    # By default OpenCV stores images in BGR format and since pytesseract assumes RGB format,
    # we need to convert from BGR to RGB format/mode:
    img_rgb = cv2.cvtColor(img_cv, cv2.COLOR_BGR2RGB)
    print(pytesseract.image_to_string(img_rgb))
    # OR
    img_rgb = Image.frombytes('RGB', img_cv.shape[:2], img_cv, 'raw', 'BGR', 0, 0)
    print(pytesseract.image_to_string(img_rgb))

# Définir l'interface utilisateur Gradio
inputs = gr.inputs.Image()
outputs = gr.outputs.Textbox()
interface = gr.Interface(fn=extract_text, inputs=inputs, outputs=outputs, 
                         title="Extraction de texte à partir d'une image", 
                         description="Téléchargez une image contenant du texte et cliquez sur 'Predict' pour extraire le texte.")
                         
interface.launch()