Rajiv Shah commited on
Commit
da3b44f
β€’
1 Parent(s): 9373e2d

added color code

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -27,8 +27,15 @@ image = Image.open("./test0.jpeg")
27
  # define id2label, label2color
28
  labels = dataset.features['ner_tags'].feature.names
29
  id2label = {v: k for v, k in enumerate(labels)}
30
- print(id2label)
31
- label2color = {'question':'blue', 'answer':'green', 'header':'orange', 'other':'violet'}
 
 
 
 
 
 
 
32
 
33
  def unnormalize_box(bbox, width, height):
34
  return [
@@ -74,10 +81,10 @@ def process_image(image):
74
  return image
75
 
76
 
77
- title = "Interactive demo: LayoutLMv2"
78
- description = "Demo for Microsoft's LayoutLMv2, a Transformer for state-of-the-art document image understanding tasks. This particular model is fine-tuned on FUNSD, a dataset of manually annotated forms. It annotates the words appearing in the image as QUESTION/ANSWER/HEADER/OTHER. 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'."
79
- article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2012.14740' target='_blank'>LayoutLMv2: Multi-modal Pre-training for Visually-Rich Document Understanding</a> | <a href='https://github.com/microsoft/unilm' target='_blank'>Github Repo</a></p>"
80
- examples =[['document.png']]
81
 
82
  css = ".output-image, .input-image {height: 40rem !important; width: 100% !important;}"
83
  #css = "@media screen and (max-width: 600px) { .output_image, .input_image {height:20rem !important; width: 100% !important;} }"
 
27
  # define id2label, label2color
28
  labels = dataset.features['ner_tags'].feature.names
29
  id2label = {v: k for v, k in enumerate(labels)}
30
+
31
+ label_ints = np.random.randint(0, len(PIL.ImageColor.colormap.items()), 60)
32
+ label_color_pil = [k for k,_ in PIL.ImageColor.colormap.items()]
33
+ label_color = [label_color_pil[i] for i in label_ints]
34
+ label2color = {}
35
+ for k,v in id2label.items():
36
+ label2color[v[2:]]=label_color[k]
37
+
38
+ #label2color = {'question':'blue', 'answer':'green', 'header':'orange', 'other':'violet'}
39
 
40
  def unnormalize_box(bbox, width, height):
41
  return [
 
81
  return image
82
 
83
 
84
+ title = "Interactive demo: LayoutLMv3"
85
+ description = "Demo for Microsoft's LayoutLMv3, a Transformer for state-of-the-art document image understanding tasks. This particular model is fine-tuned on FUNSD, a dataset of manually annotated forms. It annotates the words appearing in the image as QUESTION/ANSWER/HEADER/OTHER. 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'."
86
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2204.08387' target='_blank'>LayoutLMv2: Multi-modal Pre-training for Visually-Rich Document Understanding</a> | <a href='https://github.com/microsoft/unilm' target='_blank'>Github Repo</a></p>"
87
+ examples =[['test0.jpeg','test1.jpeg','test2.jpeg']]
88
 
89
  css = ".output-image, .input-image {height: 40rem !important; width: 100% !important;}"
90
  #css = "@media screen and (max-width: 600px) { .output_image, .input_image {height:20rem !important; width: 100% !important;} }"