intuitive262 commited on
Commit
86115e8
·
1 Parent(s): 054c08e

Update code files

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -3,14 +3,13 @@ from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoPro
3
  import torch
4
  from qwen_vl_utils import process_vision_info
5
  from PIL import Image
6
- import os
7
  import re
8
  import gradio as gr
9
 
10
  rag = RAGMultiModalModel.from_pretrained("vidore/colpali")
11
  vlm = Qwen2VLForConditionalGeneration.from_pretrained(
12
  "Qwen/Qwen2-VL-2B-Instruct",
13
- torch_dtype=torch.float16,
14
  trust_remote_code=True,
15
  device_map="auto",
16
  )
@@ -50,8 +49,8 @@ def post_process_text(text):
50
  def ocr(image):
51
  queries = [
52
  "Extract and transcribe all the text visible in the image, including any small or partially visible text.",
53
- "Look closely at the image and list any text you see, no matter how small or unclear.",
54
- "What text can you identify in this image? Include everything, even if it's partially obscured or in the background."
55
  ]
56
 
57
  all_extracted_text = []
@@ -71,6 +70,8 @@ def main_fun(image, keyword):
71
 
72
  if keyword:
73
  highlight_text = re.sub(f'({re.escape(keyword)})', r'<span style="background-color: yellow;">\1</span>', ext_text, flags=re.IGNORECASE)
 
 
74
 
75
  return ext_text, highlight_text
76
 
 
3
  import torch
4
  from qwen_vl_utils import process_vision_info
5
  from PIL import Image
 
6
  import re
7
  import gradio as gr
8
 
9
  rag = RAGMultiModalModel.from_pretrained("vidore/colpali")
10
  vlm = Qwen2VLForConditionalGeneration.from_pretrained(
11
  "Qwen/Qwen2-VL-2B-Instruct",
12
+ torch_dtype=torch.float32,
13
  trust_remote_code=True,
14
  device_map="auto",
15
  )
 
49
  def ocr(image):
50
  queries = [
51
  "Extract and transcribe all the text visible in the image, including any small or partially visible text.",
52
+ # "Look closely at the image and list any text you see, no matter how small or unclear.",
53
+ # "What text can you identify in this image? Include everything, even if it's partially obscured or in the background."
54
  ]
55
 
56
  all_extracted_text = []
 
70
 
71
  if keyword:
72
  highlight_text = re.sub(f'({re.escape(keyword)})', r'<span style="background-color: yellow;">\1</span>', ext_text, flags=re.IGNORECASE)
73
+ else:
74
+ highlight_text = ext_text
75
 
76
  return ext_text, highlight_text
77