Spaces:
Runtime error
Runtime error
update space
Browse files- .gitignore +1 -0
- app.py +20 -10
- requirements.txt +1 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
/.env
|
app.py
CHANGED
|
@@ -1,24 +1,34 @@
|
|
| 1 |
import os
|
| 2 |
-
os.system('pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html')
|
| 3 |
-
credentials_kwargs={"aws_access_key_id": os.environ["ACCESS_KEY"],"aws_secret_access_key": os.environ["SECRET_KEY"]}
|
| 4 |
-
|
| 5 |
-
# work around: https://discuss.huggingface.co/t/how-to-install-a-specific-version-of-gradio-in-spaces/13552
|
| 6 |
-
os.system("pip uninstall -y gradio")
|
| 7 |
-
os.system("pip install gradio==3.4.1")
|
| 8 |
-
os.system(os.environ["DD_ADDONS"])
|
| 9 |
-
|
| 10 |
import time
|
|
|
|
| 11 |
from os import getcwd, path, environ
|
| 12 |
import deepdoctection as dd
|
| 13 |
from deepdoctection.dataflow.serialize import DataFromList
|
| 14 |
-
|
| 15 |
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 |
from botocore.config import Config
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
_DD_ONE = "conf_dd_one.yaml"
|
| 23 |
_XSL_PATH = get_xsl_path()
|
| 24 |
|
|
@@ -207,7 +217,7 @@ def analyze_image(img, pdf, max_datapoints):
|
|
| 207 |
out = dp.as_dict()
|
| 208 |
jsonl_out.append(out)
|
| 209 |
out.pop("_image")
|
| 210 |
-
layout_items = dp.layouts
|
| 211 |
layout_items.sort(key=lambda x: x.reading_order)
|
| 212 |
layout_items_str += f"\n\n -------- PAGE NUMBER: {dp.page_number+1} ------------- \n"
|
| 213 |
for item in layout_items:
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import time
|
| 3 |
+
import importlib.metadata
|
| 4 |
from os import getcwd, path, environ
|
| 5 |
import deepdoctection as dd
|
| 6 |
from deepdoctection.dataflow.serialize import DataFromList
|
|
|
|
| 7 |
from dd_addons.extern import PdfTextDetector, PostProcessor, get_xsl_path
|
| 8 |
from dd_addons.pipe.conn import PostProcessorService
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
from botocore.config import Config
|
| 12 |
+
from dotenv import load_dotenv
|
| 13 |
+
|
| 14 |
+
load_dotenv()
|
| 15 |
|
| 16 |
|
| 17 |
+
def check_additional_requirements():
|
| 18 |
+
if not dd.detectron2_available():
|
| 19 |
+
os.system('pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html')
|
| 20 |
+
if importlib.util.find_spec("gradio") is not None:
|
| 21 |
+
if importlib.metadata.version("gradio")!="3.4.1":
|
| 22 |
+
os.system("pip uninstall -y gradio")
|
| 23 |
+
os.system("pip install gradio==3.4.1")
|
| 24 |
+
else:
|
| 25 |
+
os.system("pip install gradio==3.4.1")
|
| 26 |
+
os.system(os.environ["DD_ADDONS"])
|
| 27 |
+
return
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
check_additional_requirements()
|
| 31 |
+
# work around: https://discuss.huggingface.co/t/how-to-install-a-specific-version-of-gradio-in-spaces/13552
|
| 32 |
_DD_ONE = "conf_dd_one.yaml"
|
| 33 |
_XSL_PATH = get_xsl_path()
|
| 34 |
|
|
|
|
| 217 |
out = dp.as_dict()
|
| 218 |
jsonl_out.append(out)
|
| 219 |
out.pop("_image")
|
| 220 |
+
layout_items = [layout for layout in dp.layouts if layout.reading_order is not None]
|
| 221 |
layout_items.sort(key=lambda x: x.reading_order)
|
| 222 |
layout_items_str += f"\n\n -------- PAGE NUMBER: {dp.page_number+1} ------------- \n"
|
| 223 |
for item in layout_items:
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
Pillow==9.5.0
|
| 2 |
torch==1.12.0
|
| 3 |
torchvision==0.13.0
|
|
|
|
| 1 |
+
python-dotenv
|
| 2 |
Pillow==9.5.0
|
| 3 |
torch==1.12.0
|
| 4 |
torchvision==0.13.0
|