pierreguillou commited on
Commit
1cededf
·
1 Parent(s): a8daeee

num instances

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -49,8 +49,10 @@ def analyze_image(img):
49
  instance_mode=ColorMode.SEGMENTATION)
50
  result = v.draw_instance_predictions(output.to("cpu"))
51
  result_image = result.get_image()[:, :, ::-1]
 
 
52
 
53
- return result_image, output
54
 
55
  title = "Interactive demo: Document Layout Analysis with DiT"
56
  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'."
@@ -60,7 +62,7 @@ css = ".output-image, .input-image, .image-preview {height: 600px !important}"
60
 
61
  iface = gr.Interface(fn=analyze_image,
62
  inputs=gr.inputs.Image(type="numpy", label="document image"),
63
- outputs=[gr.outputs.Image(type="numpy", label="annotated document"), gr.outputs.Textbox(label="instances from layout detection")],
64
  title=title,
65
  description=description,
66
  examples=examples,
 
49
  instance_mode=ColorMode.SEGMENTATION)
50
  result = v.draw_instance_predictions(output.to("cpu"))
51
  result_image = result.get_image()[:, :, ::-1]
52
+
53
+ num_instances = len(output)
54
 
55
+ return result_image, num_instances
56
 
57
  title = "Interactive demo: Document Layout Analysis with DiT"
58
  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'."
 
62
 
63
  iface = gr.Interface(fn=analyze_image,
64
  inputs=gr.inputs.Image(type="numpy", label="document image"),
65
+ outputs=[gr.outputs.Image(type="numpy", label="annotated document"), gr.outputs.Textbox(label="num instances")],
66
  title=title,
67
  description=description,
68
  examples=examples,