ken4 commited on
Commit
07a8a9a
·
verified ·
1 Parent(s): 589565d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -6,7 +6,7 @@ import gradio as gr
6
  import torch
7
  import easyocr
8
 
9
- # Download examples
10
  urls = {
11
  "english.png": "https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png",
12
  "thai.jpg": "https://github.com/JaidedAI/EasyOCR/raw/master/examples/thai.jpg",
@@ -27,17 +27,18 @@ def draw_boxes(image, bounds, color='yellow', width=2):
27
  draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
28
  return image
29
 
30
- def inference(img_path, lang):
 
31
  reader = easyocr.Reader(lang)
32
  bounds = reader.readtext(img_path)
33
-
34
  im = PIL.Image.open(img_path)
35
  draw_boxes(im, bounds)
36
  im.save("result.jpg")
37
 
38
  df = pd.DataFrame(bounds)[[1, 2]]
39
  df.columns = ["text", "confidence"]
40
-
41
  return "result.jpg", df
42
 
43
  choices = [
@@ -61,16 +62,17 @@ examples = [
61
  with gr.Blocks(css=".output_image, .input_image {height: 40rem; width: 100%;}") as demo:
62
 
63
  gr.Markdown("# **EasyOCR**")
64
- gr.Markdown("Upload an image and select languages to extract text.")
65
 
66
  with gr.Row():
67
- image_input = gr.Image(type="filepath", label="Input Image")
 
68
  lang_input = gr.CheckboxGroup(choices=choices, value=["en"], label="Language")
69
 
70
  run_btn = gr.Button("Run OCR")
71
 
72
  with gr.Row():
73
- output_img = gr.Image(label="Output")
74
  output_df = gr.Dataframe(headers=["text", "confidence"], label="Detected Text")
75
 
76
  gr.Examples(examples, [image_input, lang_input], [output_img, output_df], fn=inference)
 
6
  import torch
7
  import easyocr
8
 
9
+ # Download example files
10
  urls = {
11
  "english.png": "https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png",
12
  "thai.jpg": "https://github.com/JaidedAI/EasyOCR/raw/master/examples/thai.jpg",
 
27
  draw.line([*p0, *p1, *p2, *p3, *p0], fill=color, width=width)
28
  return image
29
 
30
+ def inference(img_file, lang):
31
+ img_path = img_file.name # file object -> path
32
  reader = easyocr.Reader(lang)
33
  bounds = reader.readtext(img_path)
34
+
35
  im = PIL.Image.open(img_path)
36
  draw_boxes(im, bounds)
37
  im.save("result.jpg")
38
 
39
  df = pd.DataFrame(bounds)[[1, 2]]
40
  df.columns = ["text", "confidence"]
41
+
42
  return "result.jpg", df
43
 
44
  choices = [
 
62
  with gr.Blocks(css=".output_image, .input_image {height: 40rem; width: 100%;}") as demo:
63
 
64
  gr.Markdown("# **EasyOCR**")
65
+ gr.Markdown("Upload an image and select output languages.")
66
 
67
  with gr.Row():
68
+ # 🔥 FIX DI SINI → tidak auto-masuk galeri lagi
69
+ image_input = gr.Image(type="file", label="Input Image")
70
  lang_input = gr.CheckboxGroup(choices=choices, value=["en"], label="Language")
71
 
72
  run_btn = gr.Button("Run OCR")
73
 
74
  with gr.Row():
75
+ output_img = gr.Image(label="Detected Image")
76
  output_df = gr.Dataframe(headers=["text", "confidence"], label="Detected Text")
77
 
78
  gr.Examples(examples, [image_input, lang_input], [output_img, output_df], fn=inference)