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()