ayymen commited on
Commit
4a58ad9
1 Parent(s): 7667d72

Add choice between the Tifinagh-IRCAM and the full Tifinagh character set models.

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -4,17 +4,20 @@ from doctr.models import ocr_predictor, from_hub
4
  import gradio as gr
5
 
6
  os.environ['USE_TORCH'] = '1'
7
- reco_model = from_hub('ayymen/crnn_mobilenet_v3_large_zgh')
 
 
 
8
  predictor = ocr_predictor(reco_arch=reco_model, pretrained=True)
9
 
10
  title = "Tifinagh OCR"
11
  description = """Upload an image to get the OCR results!
12
  Thanks to @iseddik for the data!"""
13
 
14
- def ocr(img):
15
  img.save("out.jpg")
16
  doc = DocumentFile.from_images("out.jpg")
17
- output = predictor(doc)
18
  res = ""
19
  for obj in output.pages:
20
  for obj1 in obj.blocks:
@@ -31,14 +34,21 @@ def ocr(img):
31
  return res, _output_name
32
 
33
  demo = gr.Interface(fn=ocr,
34
- inputs=gr.Image(type="pil"),
 
 
 
35
  outputs=[
36
  gr.Textbox(lines=10, label="Full Text"),
37
  gr.File(label="Download OCR Results")
38
  ],
39
  title=title,
40
  description=description,
41
- examples=[["Examples/1.jpg"],["Examples/2.jpg"],["Examples/3.png"]]
 
 
 
 
42
  )
43
 
44
  demo.launch(debug=True)
 
4
  import gradio as gr
5
 
6
  os.environ['USE_TORCH'] = '1'
7
+ reco_model_zgh = from_hub('ayymen/crnn_mobilenet_v3_large_zgh')
8
+ predictor_zgh = ocr_predictor(reco_arch=reco_model_zgh, pretrained=True)
9
+
10
+ reco_model = from_hub('ayymen/crnn_mobilenet_v3_large_tifinagh')
11
  predictor = ocr_predictor(reco_arch=reco_model, pretrained=True)
12
 
13
  title = "Tifinagh OCR"
14
  description = """Upload an image to get the OCR results!
15
  Thanks to @iseddik for the data!"""
16
 
17
+ def ocr(img, script):
18
  img.save("out.jpg")
19
  doc = DocumentFile.from_images("out.jpg")
20
+ output = predictor_zgh(doc) if script == "Tifinagh-IRCAM" else predictor(doc)
21
  res = ""
22
  for obj in output.pages:
23
  for obj1 in obj.blocks:
 
34
  return res, _output_name
35
 
36
  demo = gr.Interface(fn=ocr,
37
+ inputs=[
38
+ gr.Image(type="pil"),
39
+ gr.Dropdown(choices=['Tifinagh-IRCAM', 'Tifinagh'], label="Script", value="Tifinagh-IRCAM")
40
+ ],
41
  outputs=[
42
  gr.Textbox(lines=10, label="Full Text"),
43
  gr.File(label="Download OCR Results")
44
  ],
45
  title=title,
46
  description=description,
47
+ examples=[
48
+ ["Examples/3.jpg", "Tifinagh-IRCAM"],
49
+ ["Examples/2.jpg", "Tifinagh-IRCAM"],
50
+ ["Examples/1.png", "Tifinagh-IRCAM"]
51
+ ]
52
  )
53
 
54
  demo.launch(debug=True)