gizemsarsinlar commited on
Commit
78fdfd0
1 Parent(s): bcc6570

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
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, coordinates: List[int] = None):
9
  # Görseli yükle
10
  image = Image.open(filepath)
11
 
@@ -15,7 +15,7 @@ def tesseract_ocr_with_selection(filepath: str, coordinates: List[int] = None):
15
  image = image.crop((x1, y1, x2, y2))
16
 
17
  # OCR işlemi
18
- return pytesseract.image_to_string(image=image)
19
 
20
  def draw_selection_box(image):
21
  # Görseli numpy formatına çevir
@@ -27,30 +27,32 @@ def draw_selection_box(image):
27
 
28
  # Gradio UI ayarları
29
  title = "Tesseract OCR with Selection"
 
 
30
 
31
- # examples = [
32
- # ['examples/eurotext.png', ['eng'], [50, 50, 200, 200]],
33
- # ['examples/tesseract_sample.png', ['jpn', 'eng'], [30, 40, 150, 120]],
34
- # ]
35
 
36
- # language_choices = pytesseract.get_languages()
37
 
38
  with gr.Blocks() as demo:
39
  with gr.Row():
40
  gr.Markdown("# Tesseract OCR with Selection")
41
  with gr.Row():
42
  img_input = gr.Image(type="filepath", label="Input Image")
43
- lang_input = gr.CheckboxGroup(type="value", value=['eng'], label='Language')
44
  coords_input = gr.Textbox(label="Selection Coordinates (x1, y1, x2, y2)", placeholder="50, 50, 200, 200")
45
  with gr.Row():
46
  ocr_button = gr.Button("Run OCR with Selection")
47
  with gr.Row():
48
  ocr_output = gr.Textbox(label="OCR Result")
49
 
50
- def run_with_selection(image_path, coordinates):
51
  if coordinates:
52
  coordinates = [int(coord) for coord in coordinates.split(",")]
53
- return tesseract_ocr_with_selection(image_path, coordinates)
54
 
55
  ocr_button.click(
56
  run_with_selection,
 
5
  import cv2
6
  import numpy as np
7
 
8
+ def tesseract_ocr_with_selection(filepath: str, languages: List[str], coordinates: List[int] = None):
9
  # Görseli yükle
10
  image = Image.open(filepath)
11
 
 
15
  image = image.crop((x1, y1, x2, y2))
16
 
17
  # OCR işlemi
18
+ return pytesseract.image_to_string(image=image, lang=', '.join(languages))
19
 
20
  def draw_selection_box(image):
21
  # Görseli numpy formatına çevir
 
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', ['eng'], [50, 50, 200, 200]],
35
+ ['examples/tesseract_sample.png', ['jpn', 'eng'], [30, 40, 150, 120]],
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, languages, coordinates):
53
  if coordinates:
54
  coordinates = [int(coord) for coord in coordinates.split(",")]
55
+ return tesseract_ocr_with_selection(image_path, languages, coordinates)
56
 
57
  ocr_button.click(
58
  run_with_selection,