Spaces:
Sleeping
Sleeping
juhoinkinen
commited on
Commit
·
08a4b4e
1
Parent(s):
bb1f071
Make project selectable
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr, pytesseract, cv2, os
|
|
2 |
from annif_client import AnnifClient
|
3 |
|
4 |
|
5 |
-
def process(image: str,
|
6 |
try:
|
7 |
img = cv2.imread(image)
|
8 |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
@@ -11,12 +11,8 @@ def process(image: str, proj: str, lang: str = "eng"):
|
|
11 |
)[1]
|
12 |
text = pytesseract.image_to_string(threshold_img, lang=lang)
|
13 |
os.remove(image)
|
14 |
-
results = annif.suggest(
|
15 |
-
|
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), []
|
@@ -24,14 +20,15 @@ def process(image: str, proj: str, lang: str = "eng"):
|
|
24 |
|
25 |
annif = AnnifClient()
|
26 |
langs = pytesseract.get_languages()
|
27 |
-
|
|
|
28 |
|
29 |
|
30 |
interface = gr.Interface(
|
31 |
process,
|
32 |
[
|
33 |
gr.Image(type="filepath", mirror_webcam=False),
|
34 |
-
gr.Dropdown(label="Select Project", choices=
|
35 |
gr.Dropdown(label="Select Language", choices=langs, type="value"),
|
36 |
],
|
37 |
outputs=["text", "text"],
|
|
|
2 |
from annif_client import AnnifClient
|
3 |
|
4 |
|
5 |
+
def process(image: str, project_num: int, lang: str = "eng"):
|
6 |
try:
|
7 |
img = cv2.imread(image)
|
8 |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
|
|
11 |
)[1]
|
12 |
text = pytesseract.image_to_string(threshold_img, lang=lang)
|
13 |
os.remove(image)
|
14 |
+
results = annif.suggest(project_id=proj_ids[project_num], text=text)
|
15 |
+
results = [f"{res['label']} {res['score']}" for res in results]
|
|
|
|
|
|
|
|
|
16 |
return text, results
|
17 |
except Exception as e:
|
18 |
return str(e), []
|
|
|
20 |
|
21 |
annif = AnnifClient()
|
22 |
langs = pytesseract.get_languages()
|
23 |
+
proj_ids = [project["project_id"] for project in annif.projects]
|
24 |
+
proj_names = [project["name"] for project in annif.projects]
|
25 |
|
26 |
|
27 |
interface = gr.Interface(
|
28 |
process,
|
29 |
[
|
30 |
gr.Image(type="filepath", mirror_webcam=False),
|
31 |
+
gr.Dropdown(label="Select Project", choices=proj_names, type="index"),
|
32 |
gr.Dropdown(label="Select Language", choices=langs, type="value"),
|
33 |
],
|
34 |
outputs=["text", "text"],
|