Spaces:
Running
Running
UniquePratham
commited on
Commit
•
99c8074
1
Parent(s):
6cd9e3d
Update app.py
Browse files
app.py
CHANGED
@@ -80,10 +80,14 @@ def polish_text_with_ai(cleaned_text):
|
|
80 |
return polished_text
|
81 |
|
82 |
# Extract text using GOT
|
|
|
|
|
83 |
def extract_text_got(image_file, model, tokenizer):
|
84 |
return model.chat(tokenizer, image_file, ocr_type='ocr')
|
85 |
|
86 |
# Extract text using Qwen
|
|
|
|
|
87 |
def extract_text_qwen(image_file, model, processor):
|
88 |
try:
|
89 |
image = Image.open(image_file).convert('RGB')
|
@@ -103,14 +107,14 @@ def extract_text_qwen(image_file, model, processor):
|
|
103 |
# Function to highlight the keyword in the text
|
104 |
|
105 |
|
106 |
-
def highlight_text(cleaned_text,start,end):
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
)
|
114 |
|
115 |
|
116 |
# Title and UI
|
@@ -129,7 +133,8 @@ uploaded_file = st.sidebar.file_uploader(
|
|
129 |
|
130 |
# Input from clipboard
|
131 |
# Paste image button
|
132 |
-
image_data =
|
|
|
133 |
if image_data is not None:
|
134 |
clipboard_use = True
|
135 |
header, encoded = image_data.split(",", 1)
|
@@ -217,6 +222,6 @@ if uploaded_file:
|
|
217 |
len = search_query.length
|
218 |
end = index + len
|
219 |
if index != -1:
|
220 |
-
highlight_text(cleaned_text,start,end)
|
221 |
else:
|
222 |
st.write("No Search Found.")
|
|
|
80 |
return polished_text
|
81 |
|
82 |
# Extract text using GOT
|
83 |
+
|
84 |
+
|
85 |
def extract_text_got(image_file, model, tokenizer):
|
86 |
return model.chat(tokenizer, image_file, ocr_type='ocr')
|
87 |
|
88 |
# Extract text using Qwen
|
89 |
+
|
90 |
+
|
91 |
def extract_text_qwen(image_file, model, processor):
|
92 |
try:
|
93 |
image = Image.open(image_file).convert('RGB')
|
|
|
107 |
# Function to highlight the keyword in the text
|
108 |
|
109 |
|
110 |
+
def highlight_text(cleaned_text, start, end):
|
111 |
+
text_highlighter(
|
112 |
+
text=cleaned_text,
|
113 |
+
labels=[("KEYWORD", "#0000FF")],
|
114 |
+
annotations=[
|
115 |
+
{"start": start, "end": end, "tag": "KEYWORD"},
|
116 |
+
],
|
117 |
+
)
|
118 |
|
119 |
|
120 |
# Title and UI
|
|
|
133 |
|
134 |
# Input from clipboard
|
135 |
# Paste image button
|
136 |
+
image_data = paste(
|
137 |
+
label="Paste From Clipboard", key="image_clipboard")
|
138 |
if image_data is not None:
|
139 |
clipboard_use = True
|
140 |
header, encoded = image_data.split(",", 1)
|
|
|
222 |
len = search_query.length
|
223 |
end = index + len
|
224 |
if index != -1:
|
225 |
+
highlight_text(cleaned_text, start, end)
|
226 |
else:
|
227 |
st.write("No Search Found.")
|