Atulit23 commited on
Commit
9dc8196
·
verified ·
1 Parent(s): 3dc1d86

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +3 -9
  2. app.py +49 -0
  3. requirements.txt +9 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Ocr Model
3
- emoji: 🐨
4
- colorFrom: green
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 4.16.0
8
  app_file: app.py
9
- pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: ocr_model
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 3.44.4
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from paddleocr import PaddleOCR
2
+ import requests
3
+ import numpy as np
4
+ from PIL import Image
5
+ from io import BytesIO
6
+ import json
7
+ import gradio as gr
8
+
9
+ ocr = PaddleOCR(use_angle_cls=True, lang='en', use_pdserving=False, cls_batch_num=8, det_batch_num=8, rec_batch_num=8)
10
+
11
+ def index(url):
12
+ response = requests.get(url)
13
+ img = Image.open(BytesIO(response.content))
14
+ resize_factor = 1
15
+ new_size = tuple(int(dim * resize_factor) for dim in img.size)
16
+ img = img.resize(new_size, Image.Resampling.LANCZOS)
17
+
18
+ img_array = np.array(img.convert('RGB'))
19
+
20
+ result = ocr.ocr(img_array)
21
+
22
+ boxes = [line[0] for line in result]
23
+ txts = [line[1][0] for line in result]
24
+ scores = [line[1][1] for line in result]
25
+
26
+ print(boxes)
27
+ print(txts)
28
+
29
+ output_dict = {"texts": txts, "boxes": boxes, "scores": scores}
30
+ output_json = json.dumps(output_dict) # Convert to JSON string
31
+
32
+ return output_json
33
+
34
+
35
+ inputs_image_url = [
36
+ gr.Textbox(type="text", label="Image URL"),
37
+ ]
38
+
39
+ outputs_result_json = [
40
+ gr.Textbox(type="text", label="Result JSON"),
41
+ ]
42
+
43
+ interface_image_url = gr.Interface(
44
+ fn=index,
45
+ inputs=inputs_image_url,
46
+ outputs=outputs_result_json,
47
+ title="Text Extraction",
48
+ cache_examples=False,
49
+ ).queue().launch()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ common
2
+ paddlepaddle
3
+ paddleocr
4
+ opencv-python
5
+ Shapely
6
+ requests
7
+ numpy
8
+ pillow
9
+ gradio