| import gradio as gr |
| from PIL import Image |
| import pytesseract |
|
|
|
|
| def recognize_text(image): |
| img = Image.fromarray(image.astype('uint8'), 'RGB') |
| text = pytesseract.image_to_string(img) |
| return text |
|
|
|
|
| input_image = gr.inputs.Image() |
| output_text = gr.outputs.Textbox() |
|
|
| interface = gr.Interface( |
| fn=recognize_text, |
| inputs=input_image, |
| outputs=output_text, |
| title='Image Text Recognition', |
| description='Upload an image to recognize text from it.', |
| examples=[['image/image4.jpg']], |
| allow_flagging=False |
| ) |
|
|
| if __name__ == '__main__': |
| interface.launch(share=True) |
|
|