onursavas commited on
Commit
a167d69
1 Parent(s): fd60c64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -1,9 +1,13 @@
1
  import os
2
- os.system('pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html')
 
3
  os.system("git clone https://github.com/microsoft/unilm.git")
 
 
4
 
5
  import sys
6
  sys.path.append("unilm")
 
7
 
8
  import cv2
9
 
@@ -26,7 +30,7 @@ add_vit_config(cfg)
26
  cfg.merge_from_file("cascade_dit_base.yml")
27
 
28
  # Step 2: add model weights URL to config
29
- cfg.MODEL.WEIGHTS = "https://layoutlm.blob.core.windows.net/dit/dit-fts/publaynet_dit-b_cascade.pth"
30
 
31
  # Step 3: set device
32
  cfg.MODEL.DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
@@ -52,10 +56,10 @@ def analyze_image(img):
52
 
53
  return result_image
54
 
55
- title = "Document Layout Analysis"
56
- description = ""
57
- article = ""
58
- examples =[['publaynet_example.jpeg'] ,['russian.png'],['another.png']]
59
  css = ".output-image, .input-image, .image-preview {height: 600px !important}"
60
 
61
  iface = gr.Interface(fn=analyze_image,
 
1
  import os
2
+ os.system('git clone https://github.com/facebookresearch/detectron2.git')
3
+ os.system('pip install -e detectron2')
4
  os.system("git clone https://github.com/microsoft/unilm.git")
5
+ os.system("sed -i 's/from collections import Iterable/from collections.abc import Iterable/' unilm/dit/object_detection/ditod/table_evaluation/data_structure.py")
6
+ os.system("curl -LJ -o publaynet_dit-b_cascade.pth 'https://layoutlm.blob.core.windows.net/dit/dit-fts/publaynet_dit-b_cascade.pth?sv=2022-11-02&ss=b&srt=o&sp=r&se=2033-06-08T16:48:15Z&st=2023-06-08T08:48:15Z&spr=https&sig=a9VXrihTzbWyVfaIDlIT1Z0FoR1073VB0RLQUMuudD4%3D'")
7
 
8
  import sys
9
  sys.path.append("unilm")
10
+ sys.path.append("detectron2")
11
 
12
  import cv2
13
 
 
30
  cfg.merge_from_file("cascade_dit_base.yml")
31
 
32
  # Step 2: add model weights URL to config
33
+ cfg.MODEL.WEIGHTS = "publaynet_dit-b_cascade.pth"
34
 
35
  # Step 3: set device
36
  cfg.MODEL.DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
 
56
 
57
  return result_image
58
 
59
+ title = "Interactive demo: Document Layout Analysis with DiT"
60
+ description = "Demo for Microsoft's DiT, the Document Image Transformer for state-of-the-art document understanding tasks. This particular model is fine-tuned on PubLayNet, a large dataset for document layout analysis (read more at the links below). To use it, simply upload an image or use the example image below and click 'Submit'. Results will show up in a few seconds. If you want to make the output bigger, right-click on it and select 'Open image in new tab'."
61
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2203.02378' target='_blank'>Paper</a> | <a href='https://github.com/microsoft/unilm/tree/master/dit' target='_blank'>Github Repo</a></p> | <a href='https://huggingface.co/docs/transformers/master/en/model_doc/dit' target='_blank'>HuggingFace doc</a></p>"
62
+ examples =[['publaynet_example.jpeg']]
63
  css = ".output-image, .input-image, .image-preview {height: 600px !important}"
64
 
65
  iface = gr.Interface(fn=analyze_image,