juhoinkinen commited on
Commit
eee7d64
·
1 Parent(s): f32b8b4

Use Annif-client with yso-en project

Browse files
Files changed (2) hide show
  1. app.py +12 -3
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr, pytesseract, cv2, os
 
2
 
3
 
4
  def process(image: str, proj: str, lang: str = "eng"):
@@ -8,15 +9,23 @@ def process(image: str, proj: str, lang: str = "eng"):
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, [proj]
 
 
 
 
 
 
14
  except Exception as e:
15
  return str(e), []
16
 
17
 
 
18
  langs = pytesseract.get_languages()
19
- projs = ("YSO", "KAUNO")
 
20
 
21
  interface = gr.Interface(
22
  process,
 
1
  import gradio as gr, pytesseract, cv2, os
2
+ from annif_client import AnnifClient
3
 
4
 
5
  def process(image: str, proj: str, lang: str = "eng"):
 
9
  threshold_img = cv2.threshold(
10
  gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU
11
  )[1]
12
+ text = pytesseract.image_to_string(threshold_img, lang=lang)
13
  os.remove(image)
14
+ results = annif.suggest(
15
+ project_id='yso-en',
16
+ text=text
17
+ )
18
+ results = [
19
+ f"{res['label']} {res['score']}" for res in results]
20
+ return text, results
21
  except Exception as e:
22
  return str(e), []
23
 
24
 
25
+ annif = AnnifClient()
26
  langs = pytesseract.get_languages()
27
+ projs = [project['name'] for project in annif.projects]
28
+
29
 
30
  interface = gr.Interface(
31
  process,
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  pytesseract
2
  gradio
3
  opencv-python
 
 
1
  pytesseract
2
  gradio
3
  opencv-python
4
+ annif-client