Rick7799 commited on
Commit
bf2bba9
·
verified ·
1 Parent(s): ede6268

Update app.py

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