Aravindh commited on
Commit
1e36507
1 Parent(s): bcdb129

init files

Browse files
Files changed (6) hide show
  1. .gitignore +1 -0
  2. Dockerfile +14 -0
  3. app.py +39 -0
  4. data/invoice.jpg +0 -0
  5. data/publay_sample.jpeg +0 -0
  6. data/simple.jpg +0 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .DS_Store
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ WORKDIR /code
7
+
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ COPY . .
13
+
14
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from multiocr import OcrEngine
3
+ from multiocr.utils import draw_bounding_boxes
4
+
5
+ # Define a function that takes an input image and processes it
6
+ def process_image(input_image, ocr_type):
7
+ # Perform y`our internal processing here
8
+ # Example: Convert the image to grayscale
9
+ ocr = OcrEngine(ocr_type)
10
+ data = ocr.text_extraction(input_image)
11
+ json_response = ocr.text_extraction_to_df(data)
12
+ output_image = draw_bounding_boxes(input_image, data)
13
+
14
+ return output_image, json_response
15
+
16
+ # Define the Gradio interface
17
+ def app():
18
+ ocr_type = gr.inputs.Dropdown(choices=["tesseract", "paddle_ocr", "easy_ocr", "aws_textract"], label="selct one ocr")
19
+ # Create an input component for uploading the image
20
+ image_input = gr.inputs.Image(label="Upload Image", type="filepath")
21
+
22
+ # Create an output component for displaying the processed image
23
+ image_output = gr.outputs.Image(label="Output Image", type="pil")
24
+
25
+ # Create an output component for displaying the JSON response
26
+ df = gr.outputs.Dataframe(label="DataFrame", type="pandas")
27
+
28
+ # Create a function that will be called when the app is run
29
+ def process_and_display_image(input_image, ocr_type):
30
+ processed_image, json_response = process_image(input_image, ocr_type)
31
+ return processed_image, json_response
32
+
33
+ # Create the Gradio interface
34
+ examples = [["./data/simple.jpg"], ["./data/invoice.jpg"], ["./data/publay_sample.jpeg"]]
35
+ gr.Interface(fn=process_and_display_image, inputs=[image_input, ocr_type], outputs=[image_output, df], examples=examples).launch(server_port=7860,server_name="0.0.0.0")
36
+
37
+ if __name__ == "__main__":
38
+ # Run the app
39
+ app()
data/invoice.jpg ADDED
data/publay_sample.jpeg ADDED
data/simple.jpg ADDED