|
import gradio as gr |
|
import pytesseract |
|
from PIL import Image |
|
import cv2 |
|
def extract_text(image): |
|
|
|
img_cv = cv2.imread(image) |
|
|
|
|
|
img_rgb = cv2.cvtColor(img_cv, cv2.COLOR_BGR2RGB) |
|
print(pytesseract.image_to_string(img_rgb)) |
|
|
|
img_rgb = Image.frombytes('RGB', img_cv.shape[:2], img_cv, 'raw', 'BGR', 0, 0) |
|
print(pytesseract.image_to_string(img_rgb)) |
|
|
|
|
|
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() |
|
|