Spaces:
Sleeping
Sleeping
gizemsarsinlar
commited on
Commit
•
0e74751
1
Parent(s):
732231b
Update app.py
Browse files
app.py
CHANGED
@@ -17,14 +17,27 @@ def tesseract_ocr_with_selection(filepath: str, coordinates: List[int] = None):
|
|
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',
|
27 |
-
['examples/tesseract_sample.png',
|
28 |
]
|
29 |
|
30 |
with gr.Blocks() as demo:
|
@@ -39,10 +52,13 @@ with gr.Blocks() as demo:
|
|
39 |
ocr_output = gr.Textbox(label="OCR Result")
|
40 |
|
41 |
def run_with_selection(image_path, coordinates):
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
46 |
ocr_button.click(
|
47 |
run_with_selection,
|
48 |
inputs=[img_input, coords_input],
|
|
|
17 |
# OCR işlemi (varsayılan dil: İngilizce)
|
18 |
return pytesseract.image_to_string(image=image, lang='eng')
|
19 |
|
20 |
+
def parse_coordinates(coord_input: str):
|
21 |
+
"""
|
22 |
+
Kullanıcıdan alınan koordinat stringini doğrula ve liste olarak döndür.
|
23 |
+
"""
|
24 |
+
try:
|
25 |
+
# Koordinatları virgül ile ayır ve tam sayıya çevir
|
26 |
+
coords = [int(coord.strip()) for coord in coord_input.split(",")]
|
27 |
+
if len(coords) != 4:
|
28 |
+
raise ValueError("Lütfen tam olarak 4 koordinat girin (örnek: x1, y1, x2, y2).")
|
29 |
+
return coords
|
30 |
+
except ValueError:
|
31 |
+
raise ValueError("Hatalı koordinat formatı. Lütfen şu formatı kullanın: x1, y1, x2, y2.")
|
32 |
+
|
33 |
# Gradio UI ayarları
|
34 |
title = "Tesseract OCR with Selection"
|
35 |
description = "Gradio demo for Tesseract OCR with region selection (default language: English)."
|
36 |
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>"
|
37 |
|
38 |
examples = [
|
39 |
+
['examples/eurotext.png', "50, 50, 200, 200"],
|
40 |
+
['examples/tesseract_sample.png', "30, 40, 150, 120"],
|
41 |
]
|
42 |
|
43 |
with gr.Blocks() as demo:
|
|
|
52 |
ocr_output = gr.Textbox(label="OCR Result")
|
53 |
|
54 |
def run_with_selection(image_path, coordinates):
|
55 |
+
try:
|
56 |
+
# Koordinatları doğrula ve ayrıştır
|
57 |
+
coords = parse_coordinates(coordinates)
|
58 |
+
return tesseract_ocr_with_selection(image_path, coords)
|
59 |
+
except ValueError as e:
|
60 |
+
return str(e) # Kullanıcıya hata mesajı göster
|
61 |
+
|
62 |
ocr_button.click(
|
63 |
run_with_selection,
|
64 |
inputs=[img_input, coords_input],
|