JaMe76 commited on
Commit
a2e256b
·
1 Parent(s): 397d15f

update space to v.0.25

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -1,13 +1,17 @@
1
  import os
2
- os.system('pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html')
3
 
4
- credentials_kwargs={"aws_access_key_id": os.environ["ACCESS_KEY"],"aws_secret_access_key": os.environ["SECRET_KEY"]}
 
 
 
 
5
 
6
  # work around: https://discuss.huggingface.co/t/how-to-install-a-specific-version-of-gradio-in-spaces/13552
7
- os.system("pip uninstall -y gradio")
8
- os.system("pip install gradio==3.4.1")
9
  os.system(os.environ["DD_ADDONS"])
10
 
 
11
  from os import getcwd, path, environ
12
  import deepdoctection as dd
13
  from deepdoctection.dataflow.serialize import DataFromList
@@ -16,6 +20,7 @@ from dd_addons.extern import PdfTextDetector, PostProcessor, get_xsl_path
16
  from dd_addons.pipe.conn import PostProcessorService
17
 
18
  import gradio as gr
 
19
 
20
 
21
  _DD_ONE = "conf_dd_one.yaml"
@@ -97,6 +102,9 @@ d_item = dd.D2FrcnnDetector(item_config_path, item_weights_path, categories_item
97
  pdf_text = PdfTextDetector(_XSL_PATH)
98
 
99
  # text detector
 
 
 
100
  tex_text = dd.TextractOcrDetector(**credentials_kwargs)
101
 
102
 
@@ -161,9 +169,9 @@ def build_gradio_analyzer():
161
 
162
  order = dd.TextOrderService(
163
  text_container=cfg.TEXT_ORDERING.TEXT_CONTAINER,
164
- floating_text_block_names=cfg.TEXT_ORDERING.FLOATING_TEXT_BLOCK,
165
- text_block_names=cfg.TEXT_ORDERING.TEXT_BLOCK,
166
- text_containers_to_text_block=cfg.TEXT_ORDERING.TEXT_CONTAINER_TO_TEXT_BLOCK
167
  )
168
  pipe_component_list.append(order)
169
 
@@ -182,7 +190,7 @@ def analyze_image(img, pdf, max_datapoints):
182
  analyzer = build_gradio_analyzer()
183
 
184
  if img is not None:
185
- image = dd.Image(file_name="input.png", location="")
186
  image.image = img[:, :, ::-1]
187
 
188
  df = DataFromList(lst=[image])
 
1
  import os
 
2
 
3
+ os.environ["DD_ADDONS"]="pip install git+https://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@github.com/JaMe76/dd_addons.git"
4
+ os.environ["ACCESS_KEY"]="AKIAXINDAFBPHAHBJAKU"
5
+ os.environ["SECRET_KEY"]="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"
6
+ os.environ["REGION"]="eu-west-1"
7
+ os.system('pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html')
8
 
9
  # work around: https://discuss.huggingface.co/t/how-to-install-a-specific-version-of-gradio-in-spaces/13552
10
+ #os.system("pip uninstall -y gradio")
11
+ #os.system("pip install gradio==3.4.1")
12
  os.system(os.environ["DD_ADDONS"])
13
 
14
+ import time
15
  from os import getcwd, path, environ
16
  import deepdoctection as dd
17
  from deepdoctection.dataflow.serialize import DataFromList
 
20
  from dd_addons.pipe.conn import PostProcessorService
21
 
22
  import gradio as gr
23
+ from botocore.config import Config
24
 
25
 
26
  _DD_ONE = "conf_dd_one.yaml"
 
102
  pdf_text = PdfTextDetector(_XSL_PATH)
103
 
104
  # text detector
105
+ credentials_kwargs={"aws_access_key_id": os.environ["ACCESS_KEY"],
106
+ "aws_secret_access_key": os.environ["SECRET_KEY"],
107
+ "config": Config(region_name=os.environ["REGION"])}
108
  tex_text = dd.TextractOcrDetector(**credentials_kwargs)
109
 
110
 
 
169
 
170
  order = dd.TextOrderService(
171
  text_container=cfg.TEXT_ORDERING.TEXT_CONTAINER,
172
+ floating_text_block_categories=cfg.TEXT_ORDERING.FLOATING_TEXT_BLOCK,
173
+ text_block_categories=cfg.TEXT_ORDERING.TEXT_BLOCK,
174
+ include_residual_text_container=cfg.TEXT_ORDERING.TEXT_CONTAINER_TO_TEXT_BLOCK
175
  )
176
  pipe_component_list.append(order)
177
 
 
190
  analyzer = build_gradio_analyzer()
191
 
192
  if img is not None:
193
+ image = dd.Image(file_name=str(time.time()).replace(".","") + ".png", location="")
194
  image.image = img[:, :, ::-1]
195
 
196
  df = DataFromList(lst=[image])