Spaces:
Sleeping
Sleeping
gizemsarsinlar
commited on
Commit
•
732231b
1
Parent(s):
78fdfd0
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import gradio as gr
|
|
5 |
import cv2
|
6 |
import numpy as np
|
7 |
|
8 |
-
def tesseract_ocr_with_selection(filepath: str,
|
9 |
# Görseli yükle
|
10 |
image = Image.open(filepath)
|
11 |
|
@@ -14,49 +14,38 @@ def tesseract_ocr_with_selection(filepath: str, languages: List[str], coordinate
|
|
14 |
x1, y1, x2, y2 = coordinates
|
15 |
image = image.crop((x1, y1, x2, y2))
|
16 |
|
17 |
-
# OCR işlemi
|
18 |
-
return pytesseract.image_to_string(image=image, lang='
|
19 |
-
|
20 |
-
def draw_selection_box(image):
|
21 |
-
# Görseli numpy formatına çevir
|
22 |
-
image = np.array(image)
|
23 |
-
# Kullanıcıdan alan seçmesini iste
|
24 |
-
coordinates = cv2.selectROI("Alanı Seçin (ESC ile çıkın)", image, showCrosshair=True)
|
25 |
-
cv2.destroyAllWindows()
|
26 |
-
return list(coordinates)
|
27 |
|
28 |
# Gradio UI ayarları
|
29 |
title = "Tesseract OCR with Selection"
|
30 |
-
description = "Gradio demo for Tesseract OCR with region selection."
|
31 |
article = "<p style='text-align: center'><a href='https://tesseract-ocr.github.io/' target='_blank'>Tesseract documentation</a> | <a href='https://github.com/tesseract-ocr/tesseract' target='_blank'>Github Repo</a></p>"
|
32 |
|
33 |
examples = [
|
34 |
-
['examples/eurotext.png', [
|
35 |
-
['examples/tesseract_sample.png', [
|
36 |
]
|
37 |
|
38 |
-
language_choices = pytesseract.get_languages()
|
39 |
-
|
40 |
with gr.Blocks() as demo:
|
41 |
with gr.Row():
|
42 |
gr.Markdown("# Tesseract OCR with Selection")
|
43 |
with gr.Row():
|
44 |
img_input = gr.Image(type="filepath", label="Input Image")
|
45 |
-
lang_input = gr.CheckboxGroup(language_choices, type="value", value=['eng'], label='Language')
|
46 |
coords_input = gr.Textbox(label="Selection Coordinates (x1, y1, x2, y2)", placeholder="50, 50, 200, 200")
|
47 |
with gr.Row():
|
48 |
ocr_button = gr.Button("Run OCR with Selection")
|
49 |
with gr.Row():
|
50 |
ocr_output = gr.Textbox(label="OCR Result")
|
51 |
|
52 |
-
def run_with_selection(image_path,
|
53 |
if coordinates:
|
54 |
coordinates = [int(coord) for coord in coordinates.split(",")]
|
55 |
-
return tesseract_ocr_with_selection(image_path,
|
56 |
|
57 |
ocr_button.click(
|
58 |
run_with_selection,
|
59 |
-
inputs=[img_input,
|
60 |
outputs=[ocr_output]
|
61 |
)
|
62 |
|
|
|
5 |
import cv2
|
6 |
import numpy as np
|
7 |
|
8 |
+
def tesseract_ocr_with_selection(filepath: str, coordinates: List[int] = None):
|
9 |
# Görseli yükle
|
10 |
image = Image.open(filepath)
|
11 |
|
|
|
14 |
x1, y1, x2, y2 = coordinates
|
15 |
image = image.crop((x1, y1, x2, y2))
|
16 |
|
17 |
+
# OCR işlemi (varsayılan dil: İngilizce)
|
18 |
+
return pytesseract.image_to_string(image=image, lang='eng')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Gradio UI ayarları
|
21 |
title = "Tesseract OCR with Selection"
|
22 |
+
description = "Gradio demo for Tesseract OCR with region selection (default language: English)."
|
23 |
article = "<p style='text-align: center'><a href='https://tesseract-ocr.github.io/' target='_blank'>Tesseract documentation</a> | <a href='https://github.com/tesseract-ocr/tesseract' target='_blank'>Github Repo</a></p>"
|
24 |
|
25 |
examples = [
|
26 |
+
['examples/eurotext.png', [50, 50, 200, 200]],
|
27 |
+
['examples/tesseract_sample.png', [30, 40, 150, 120]],
|
28 |
]
|
29 |
|
|
|
|
|
30 |
with gr.Blocks() as demo:
|
31 |
with gr.Row():
|
32 |
gr.Markdown("# Tesseract OCR with Selection")
|
33 |
with gr.Row():
|
34 |
img_input = gr.Image(type="filepath", label="Input Image")
|
|
|
35 |
coords_input = gr.Textbox(label="Selection Coordinates (x1, y1, x2, y2)", placeholder="50, 50, 200, 200")
|
36 |
with gr.Row():
|
37 |
ocr_button = gr.Button("Run OCR with Selection")
|
38 |
with gr.Row():
|
39 |
ocr_output = gr.Textbox(label="OCR Result")
|
40 |
|
41 |
+
def run_with_selection(image_path, coordinates):
|
42 |
if coordinates:
|
43 |
coordinates = [int(coord) for coord in coordinates.split(",")]
|
44 |
+
return tesseract_ocr_with_selection(image_path, coordinates)
|
45 |
|
46 |
ocr_button.click(
|
47 |
run_with_selection,
|
48 |
+
inputs=[img_input, coords_input],
|
49 |
outputs=[ocr_output]
|
50 |
)
|
51 |
|