juhoinkinen commited on
Commit
0fb7b8c
Β·
1 Parent(s): 73e48e5

Switch to Gradio sdk

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +31 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -3,7 +3,7 @@ title: Annif - Text Classification and Subject Indexing
3
  emoji: πŸ“•
4
  colorFrom: purple
5
  colorTo: purple
6
- sdk: docker
7
  pinned: false
8
  tags:
9
  - glam
 
3
  emoji: πŸ“•
4
  colorFrom: purple
5
  colorTo: purple
6
+ sdk: gradio
7
  pinned: false
8
  tags:
9
  - glam
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr, pytesseract, cv2, os
2
+
3
+
4
+ def process(image: str, lang: str = "eng") -> str:
5
+ try:
6
+ img = cv2.imread(image)
7
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
8
+ threshold_img = cv2.threshold(
9
+ gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU
10
+ )[1]
11
+ result = pytesseract.image_to_string(threshold_img, lang=lang)
12
+ os.remove(image)
13
+ return result
14
+ except Exception as e:
15
+ return str(e)
16
+
17
+
18
+ langs = pytesseract.get_languages()
19
+
20
+ interface = gr.Interface(
21
+ process,
22
+ [
23
+ gr.Image(type="filepath"),
24
+ gr.Dropdown(label="Select Language", choices=langs, type="value"),
25
+ ],
26
+ outputs="text",
27
+ css="footer {visibility: hidden}",
28
+ title="Optical Character Recognition | Image To Text",
29
+ article="""<p style='text-align: center;'>Hello, thanks for coming, visit our tools: <a href="https://www.genelify.com" target="_blank">Genelify</a></p>""",
30
+ )
31
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pytesseract
2
+ gradio
3
+ opencv-python