Spaces:
Sleeping
Sleeping
Aumkeshchy2003
commited on
Commit
•
794e69a
1
Parent(s):
d4640a8
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from PIL import Image
|
3 |
-
import pytesseract
|
4 |
-
import re
|
5 |
from typing import List
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
def tesseract_ocr(filepath: str, languages: List[str]):
|
8 |
image = Image.open(filepath)
|
9 |
return pytesseract.image_to_string(image=image, lang=', '.join(languages))
|
@@ -19,31 +20,19 @@ examples = [
|
|
19 |
|
20 |
language_choices = pytesseract.get_languages()
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
return highlighted_text
|
25 |
-
|
26 |
-
def ocr_and_search(image, keyword):
|
27 |
-
if image is None:
|
28 |
-
return "Please upload an image."
|
29 |
-
|
30 |
-
extracted_text = perform_ocr(image)
|
31 |
-
|
32 |
-
if keyword:
|
33 |
-
highlighted_text = search_and_highlight(extracted_text, keyword)
|
34 |
-
return highlighted_text
|
35 |
-
else:
|
36 |
-
return extracted_text
|
37 |
-
|
38 |
-
iface = gr.Interface(
|
39 |
-
fn=ocr_and_search,
|
40 |
inputs=[
|
41 |
-
gr.Image(type="
|
42 |
-
gr.
|
43 |
-
|
44 |
-
outputs=
|
45 |
-
title=
|
46 |
-
description=
|
|
|
|
|
47 |
)
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from typing import List
|
2 |
|
3 |
+
import pytesseract
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
def tesseract_ocr(filepath: str, languages: List[str]):
|
9 |
image = Image.open(filepath)
|
10 |
return pytesseract.image_to_string(image=image, lang=', '.join(languages))
|
|
|
20 |
|
21 |
language_choices = pytesseract.get_languages()
|
22 |
|
23 |
+
demo = gr.Interface(
|
24 |
+
fn=tesseract_ocr,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
inputs=[
|
26 |
+
gr.Image(type="filepath", label="Input"),
|
27 |
+
gr.CheckboxGroup(language_choices, type="value", value=['eng'], label='language')
|
28 |
+
],
|
29 |
+
outputs='text',
|
30 |
+
title=title,
|
31 |
+
description=description,
|
32 |
+
article=article,
|
33 |
+
examples=examples,
|
34 |
)
|
35 |
|
36 |
+
if __name__ == '__main__':
|
37 |
+
demo.launch()
|
38 |
+
print("Finished running")
|