MohamedRashad commited on
Commit
2943064
1 Parent(s): ff9c5d7

Add image processing functionality and update dependencies

Browse files
Files changed (3) hide show
  1. app.py +7 -2
  2. book_page.jpeg +0 -0
  3. requirements.txt +4 -1
app.py CHANGED
@@ -1,6 +1,8 @@
1
  from transformers import NougatProcessor, VisionEncoderDecoderModel
2
  import gradio as gr
3
  import torch
 
 
4
  from pdf2image import convert_from_path
5
 
6
  # Load the model and processor
@@ -67,6 +69,8 @@ This is a demo for the Arabic Small Nougat model. It is an end-to-end OCR model
67
  **Note**: The model is a prototype in my book and may not work well on all types of images and PDFs. **Check the output carefully before using it for any serious work.**
68
  """
69
 
 
 
70
  with gr.Blocks(title="Arabic Small Nougat") as demo:
71
  gr.HTML("<h1 style='text-align: center'>Arabic End-to-End Structured OCR for textbooks</h1>")
72
  gr.Markdown(model_description)
@@ -74,10 +78,11 @@ with gr.Blocks(title="Arabic Small Nougat") as demo:
74
  with gr.Tab("Extract Text from Image"):
75
  with gr.Row():
76
  with gr.Column():
77
- image = gr.Image(label="Input Image", type="pil")
78
  image_submit_button = gr.Button(value="Submit", variant="primary")
79
  output = gr.Markdown(label="Output Markdown", rtl=True)
80
- image_submit_button.click(extract_text_from_image, inputs=[image], outputs=output)
 
81
 
82
  with gr.Tab("Extract Text from PDF"):
83
  with gr.Row():
 
1
  from transformers import NougatProcessor, VisionEncoderDecoderModel
2
  import gradio as gr
3
  import torch
4
+ from PIL import Image
5
+ from pathlib import Path
6
  from pdf2image import convert_from_path
7
 
8
  # Load the model and processor
 
69
  **Note**: The model is a prototype in my book and may not work well on all types of images and PDFs. **Check the output carefully before using it for any serious work.**
70
  """
71
 
72
+ example_images = [Image.open(Path(__file__).parent / "book_page.jpeg")]
73
+
74
  with gr.Blocks(title="Arabic Small Nougat") as demo:
75
  gr.HTML("<h1 style='text-align: center'>Arabic End-to-End Structured OCR for textbooks</h1>")
76
  gr.Markdown(model_description)
 
78
  with gr.Tab("Extract Text from Image"):
79
  with gr.Row():
80
  with gr.Column():
81
+ input_image = gr.Image(label="Input Image", type="pil")
82
  image_submit_button = gr.Button(value="Submit", variant="primary")
83
  output = gr.Markdown(label="Output Markdown", rtl=True)
84
+ image_submit_button.click(extract_text_from_image, inputs=[input_image], outputs=output)
85
+ gr.Examples(example_images, [input_image], output, extract_text_from_image, cache_examples=True)
86
 
87
  with gr.Tab("Extract Text from PDF"):
88
  with gr.Row():
book_page.jpeg ADDED
requirements.txt CHANGED
@@ -2,4 +2,7 @@ pdf2image
2
  torch
3
  transformers
4
  gradio
5
- python-Levenshtein
 
 
 
 
2
  torch
3
  transformers
4
  gradio
5
+ python-Levenshtein
6
+ pillow
7
+ pathlib
8
+ nltk