Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,18 +3,59 @@ os.system('pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/w
|
|
3 |
|
4 |
from deepdoctection.dataflow import DataFromList
|
5 |
from deepdoctection import get_dd_analyzer
|
6 |
-
|
7 |
import gradio as gr
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def analyze_image(img):
|
11 |
# creating an image object and passing to the analyzer by using dataflows
|
12 |
-
image = Image(file_name="input.png", location="")
|
13 |
image.image = img[:,:,::-1]
|
14 |
|
15 |
-
df = DataFromList(lst=[image])
|
16 |
|
17 |
-
analyzer =
|
18 |
|
19 |
df = analyzer.analyze(dataset_dataflow=df)
|
20 |
df.reset_state()
|
|
|
3 |
|
4 |
from deepdoctection.dataflow import DataFromList
|
5 |
from deepdoctection import get_dd_analyzer
|
6 |
+
import deepdoctection as dd
|
7 |
import gradio as gr
|
8 |
|
9 |
+
_DD_ONE = "deepdoctection/configs/conf_dd_one.yaml"
|
10 |
+
_TESSERACT = "deepdoctection/configs/conf_tesseract.yaml"
|
11 |
+
|
12 |
+
dd.ModelCatalog.register("layout/model_final_inf_only.pt",dd.ModelProfile(
|
13 |
+
name="layout/model_final_inf_only.pt",
|
14 |
+
description="Detectron2 layout detection model trained on private datasets",
|
15 |
+
config="dd/d2/layout/CASCADE_RCNN_R_50_FPN_GN.yaml",
|
16 |
+
size=[274632215],
|
17 |
+
tp_model=False,
|
18 |
+
hf_repo_id=os.environ.get("HF_REPO"),
|
19 |
+
hf_model_name="model_final_inf_only.pt",
|
20 |
+
hf_config_file=["Base-RCNN-FPN.yaml", "CASCADE_RCNN_R_50_FPN_GN.yaml"],
|
21 |
+
categories={"1": dd.names.C.TEXT,
|
22 |
+
"2": dd.names.C.TITLE,
|
23 |
+
"3": dd.names.C.LIST,
|
24 |
+
"4": dd.names.C.TAB,
|
25 |
+
"5": dd.names.C.FIG},
|
26 |
+
))
|
27 |
+
|
28 |
+
def get_space_dd_analyzer():
|
29 |
+
# get a dd analyzer with a special layout model
|
30 |
+
lib, device = _auto_select_lib_and_device()
|
31 |
+
dd_one_config_path = _maybe_copy_config_to_cache(_DD_ONE)
|
32 |
+
_maybe_copy_config_to_cache(_TESSERACT)
|
33 |
+
|
34 |
+
# Set up of the configuration and logging
|
35 |
+
cfg = set_config_by_yaml(dd_one_config_path)
|
36 |
+
|
37 |
+
cfg.freeze(freezed=False)
|
38 |
+
cfg.LIB = lib
|
39 |
+
cfg.DEVICE = device
|
40 |
+
cfg.TAB = tables
|
41 |
+
cfg.TAB_REF = table_refinement
|
42 |
+
cfg.OCR = ocr
|
43 |
+
cfg.LANG = language
|
44 |
+
cfg.WEIGHTS.D2LAYOUT = "layout/model_final_inf_only.pt"
|
45 |
+
cfg.freeze()
|
46 |
+
|
47 |
+
return build_analyzer(cfg)
|
48 |
+
|
49 |
+
|
50 |
|
51 |
def analyze_image(img):
|
52 |
# creating an image object and passing to the analyzer by using dataflows
|
53 |
+
image = dd.Image(file_name="input.png", location="")
|
54 |
image.image = img[:,:,::-1]
|
55 |
|
56 |
+
df = dd.DataFromList(lst=[image])
|
57 |
|
58 |
+
analyzer = get_space_dd_analyzer()
|
59 |
|
60 |
df = analyzer.analyze(dataset_dataflow=df)
|
61 |
df.reset_state()
|