File size: 1,029 Bytes
bf2bba9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import gradio as gr
from byaldi import RAGMultiModalModel # Importing the ColPali model
# Initialize the ColPali model
model = RAGMultiModalModel.from_pretrained("vidore/colpali-v1.2")
def extract_and_search(image, keyword):
# Use the model to extract text from the image
extracted_text = model.predict(image) # Replace with actual prediction method
# Perform keyword search
matching_lines = [line for line in extracted_text.splitlines() if keyword.lower() in line.lower()]
return extracted_text, matching_lines
# Create Gradio interface
interface = gr.Interface(
fn=extract_and_search,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Textbox(label="Enter Keyword")
],
outputs=[
gr.Textbox(label="Extracted Text"),
gr.Textbox(label="Matching Lines")
],
title="ColPali OCR with Keyword Search",
description="Upload an image and enter a keyword to search within the extracted text."
)
# Launch the app
interface.launch(share=True)
|