import gradio as gr import cv2 import easyocr # Initialize EasyOCR Reader reader = easyocr.Reader(['en', 'hi']) # Function to process the image def preprocess_image(image): # Convert the image to BGR format for EasyOCR return cv2.cvtColor(image, cv2.COLOR_RGB2BGR) def ocr_and_search(image, keyword): processed_image = preprocess_image(image) # Extract text in both Hindi and English results = reader.readtext(processed_image) # Combine extracted text into a single string extracted_text = "\n".join([result[1] for result in results]) # Search for the keyword in the extracted text (case insensitive) search_results = [line for line in extracted_text.split('\n') if keyword.lower() in line.lower()] return extracted_text, search_results # Create Gradio interface iface = gr.Interface( fn=ocr_and_search, inputs=[gr.Image(type="numpy"), gr.Textbox(label="Keyword")], outputs=["text", "text"], title="OCR and Keyword Search", description="Upload an image with text and search for a keyword." ) # Launch the interface iface.launch(share=True)