| import gradio as gr | |
| import easyocr | |
| # Initialize the EasyOCR Reader | |
| reader = easyocr.Reader(['en'], gpu=False) # Set gpu=True if GPU is available | |
| def extract_text_from_image(image): | |
| # Perform OCR on the image | |
| results = reader.readtext(image) | |
| # Extract detected text | |
| extracted_text = "\n".join([result[1] for result in results]) | |
| return extracted_text | |
| # Define Gradio Interface | |
| interface = gr.Interface( | |
| fn=extract_text_from_image, # Function to run | |
| inputs=gr.Image(type="filepath"), # Upload an image | |
| outputs="text", # Display extracted text | |
| title="Image Text Extractor", | |
| description="Upload an image to extract text using OCR." | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| interface.launch() | |