dimasdeffieux commited on
Commit
4d76f31
·
verified ·
1 Parent(s): a1718e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -30
app.py CHANGED
@@ -1,30 +1,26 @@
1
- from transformers import TFAutoModel, AutoTokenizer
2
-
3
- tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
4
- model = TFAutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
5
- model = model.eval().cuda()
6
-
7
-
8
- # input your test image
9
- image_file = 'input_data/ocr_input/shopping-1200-1667548245.jpg'
10
-
11
- # plain texts OCR
12
- res = model.chat(tokenizer, image_file, ocr_type='ocr')
13
-
14
- # format texts OCR:
15
- # res = model.chat(tokenizer, image_file, ocr_type='format')
16
-
17
- # fine-grained OCR:
18
- # res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_box='')
19
- # res = model.chat(tokenizer, image_file, ocr_type='format', ocr_box='')
20
- # res = model.chat(tokenizer, image_file, ocr_type='ocr', ocr_color='')
21
- # res = model.chat(tokenizer, image_file, ocr_type='format', ocr_color='')
22
-
23
- # multi-crop OCR:
24
- # res = model.chat_crop(tokenizer, image_file, ocr_type='ocr')
25
- # res = model.chat_crop(tokenizer, image_file, ocr_type='format')
26
-
27
- # render the formatted OCR results:
28
- # res = model.chat(tokenizer, image_file, ocr_type='format', render=True, save_render_file = './demo.html')
29
-
30
- print(res)
 
1
+ import os
2
+ os.system('pip install paddlepaddle')
3
+ os.system('pip install paddleocr')
4
+ import requests
5
+ from paddleocr import PaddleOCR, draw_ocr
6
+ from PIL import Image
7
+ import gradio as gr
8
+
9
+ img = "input_data/ocr_input/39890867421_3fa100d185_z.jpg"
10
+
11
+ def inference(img, lang):
12
+ ocr = PaddleOCR(use_angle_cls=True, lang=lang,use_gpu=False)
13
+ img_path = img
14
+ result = ocr.ocr(img_path, cls=True)[0]
15
+ image = Image.open(img_path).convert('RGB')
16
+ boxes = [line[0] for line in result]
17
+ txts = [line[1][0] for line in result]
18
+ scores = [line[1][1] for line in result]
19
+ return txts
20
+ # im_show = draw_ocr(image, boxes, txts, scores,
21
+ # font_path='./simfang.ttf')
22
+ # im_show = Image.fromarray(im_show)
23
+ # im_show.save('result.jpg')
24
+ # return 'result.jpg'
25
+
26
+ print(inference(img,"ko"))