RufusRubin777 commited on
Commit
588f818
·
verified ·
1 Parent(s): 34b8505

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -5,6 +5,7 @@ from byaldi import RAGMultiModalModel
5
  from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
6
  from qwen_vl_utils import process_vision_info
7
  import torch
 
8
 
9
  # Load models
10
  def load_models():
@@ -59,8 +60,26 @@ def ocr_and_search(image, keyword):
59
  keyword_lower = keyword.lower()
60
  sentences = extracted_text.split('. ')
61
  matched_sentences = [sentence for sentence in sentences if keyword_lower in sentence.lower()]
 
 
 
62
 
63
- return extracted_text, matched_sentences #, json_output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
 
66
  # Gradio App
 
5
  from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
6
  from qwen_vl_utils import process_vision_info
7
  import torch
8
+ import re
9
 
10
  # Load models
11
  def load_models():
 
60
  keyword_lower = keyword.lower()
61
  sentences = extracted_text.split('. ')
62
  matched_sentences = [sentence for sentence in sentences if keyword_lower in sentence.lower()]
63
+
64
+
65
+ #########################################################################################################################################################
66
 
67
+ highlighted_text = matched_sentences
68
+ if search_queries:
69
+ keywords = [kw.strip() for kw in search_queries.split(",")]
70
+ for keyword in keywords:
71
+ highlighted_text = re.sub(
72
+ re.escape(keyword),
73
+ f"<span style='background-color: #f1c40f; color: #000; font-weight: bold;'>{keyword}</span>",
74
+ highlighted_text,
75
+ flags=re.IGNORECASE
76
+ )
77
+
78
+
79
+ ####################################################################################################################################################
80
+
81
+
82
+ return extracted_text, highlighted_text #, json_output
83
 
84
 
85
  # Gradio App