prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Import error synthetize_page func in streamlit demo script
  ## 🐛 Bug
  
  Import bug while running the streamlit demo script
  
  ## To Reproduce
  
  Steps to reproduce the behavior:
  
  1. Install the current package version 
  2. Run streamlit demo/app.py
  
  Error message : ImportError: cannot import name 'synthetize_page' from 'doctr.utils.visualization' (/home/ubuntu/repos/mindee/doctr/doctr/utils/visualization.py)
  
  ## Correction 
  
  Try to import "synthetize_page" [from](https://github.com/mindee/doctr/blob/cfc329f8b21cd7d8c08d5c9190c53bd77a3149c4/doctr/utils/visualization.py#L19) whereas it should be "synthesize_page" [here](https://github.com/mindee/doctr/blob/cfc329f8b21cd7d8c08d5c9190c53bd77a3149c4/demo/app.py#L21) . It's probably a typo. It works after renaming.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `demo/app.py`
  Content:
  ```
  1 # Copyright (C) 2021, Mindee.
  2 
  3 # This program is licensed under the Apache License version 2.
  4 # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.
  5 
  6 import os
  7 import streamlit as st
  8 import matplotlib.pyplot as plt
  9 
  10 os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
  11 
  12 import tensorflow as tf
  13 import cv2
  14 
  15 gpu_devices = tf.config.experimental.list_physical_devices('GPU')
  16 if any(gpu_devices):
  17     tf.config.experimental.set_memory_growth(gpu_devices[0], True)
  18 
  19 from doctr.io import DocumentFile
  20 from doctr.models import ocr_predictor
  21 from doctr.utils.visualization import synthetize_page, visualize_page
  22 
  23 DET_ARCHS = ["db_resnet50"]
  24 RECO_ARCHS = ["crnn_vgg16_bn", "master", "sar_resnet31"]
  25 
  26 
  27 def main():
  28 
  29     # Wide mode
  30     st.set_page_config(layout="wide")
  31 
  32     # Designing the interface
  33     st.title("DocTR: Document Text Recognition")
  34     # For newline
  35     st.write('\n')
  36     # Instructions
  37     st.markdown("*Hint: click on the top-right corner of an image to enlarge it!*")
  38     # Set the columns
  39     cols = st.beta_columns((1, 1, 1, 1))
  40     cols[0].subheader("Input page")
  41     cols[1].subheader("Segmentation heatmap")
  42     cols[2].subheader("OCR output")
  43     cols[3].subheader("Page reconstitution")
  44 
  45     # Sidebar
  46     # File selection
  47     st.sidebar.title("Document selection")
  48     # Disabling warning
  49     st.set_option('deprecation.showfileUploaderEncoding', False)
  50     # Choose your own image
  51     uploaded_file = st.sidebar.file_uploader("Upload files", type=['pdf', 'png', 'jpeg', 'jpg'])
  52     if uploaded_file is not None:
  53         if uploaded_file.name.endswith('.pdf'):
  54             doc = DocumentFile.from_pdf(uploaded_file.read()).as_images()
  55         else:
  56             doc = DocumentFile.from_images(uploaded_file.read())
  57         page_idx = st.sidebar.selectbox("Page selection", [idx + 1 for idx in range(len(doc))]) - 1
  58         cols[0].image(doc[page_idx])
  59 
  60     # Model selection
  61     st.sidebar.title("Model selection")
  62     det_arch = st.sidebar.selectbox("Text detection model", DET_ARCHS)
  63     reco_arch = st.sidebar.selectbox("Text recognition model", RECO_ARCHS)
  64 
  65     # For newline
  66     st.sidebar.write('\n')
  67 
  68     if st.sidebar.button("Analyze page"):
  69 
  70         if uploaded_file is None:
  71             st.sidebar.write("Please upload a document")
  72 
  73         else:
  74             with st.spinner('Loading model...'):
  75                 predictor = ocr_predictor(det_arch, reco_arch, pretrained=True)
  76 
  77             with st.spinner('Analyzing...'):
  78 
  79                 # Forward the image to the model
  80                 processed_batches = predictor.det_predictor.pre_processor([doc[page_idx]])
  81                 out = predictor.det_predictor.model(processed_batches[0], return_model_output=True, training=False)
  82                 seg_map = out["out_map"]
  83                 seg_map = tf.squeeze(seg_map[0, ...], axis=[2])
  84                 seg_map = cv2.resize(seg_map.numpy(), (doc[page_idx].shape[1], doc[page_idx].shape[0]),
  85                                      interpolation=cv2.INTER_LINEAR)
  86                 # Plot the raw heatmap
  87                 fig, ax = plt.subplots()
  88                 ax.imshow(seg_map)
  89                 ax.axis('off')
  90                 cols[1].pyplot(fig)
  91 
  92                 # Plot OCR output
  93                 out = predictor([doc[page_idx]], training=False)
  94                 fig = visualize_page(out.pages[0].export(), doc[page_idx], interactive=False)
  95                 cols[2].pyplot(fig)
  96 
  97                 # Page reconsitution under input page
  98                 page_export = out.pages[0].export()
  99                 img = synthetize_page(page_export)
  100                 cols[3].image(img, clamp=True)
  101 
  102                 # Display JSON
  103                 st.markdown("\nHere are your analysis results in JSON format:")
  104                 st.json(page_export)
  105 
  106 
  107 if __name__ == '__main__':
  108     main()
  109
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/demo/app.py b/demo/app.py
  --- a/demo/app.py
  +++ b/demo/app.py
  @@ -18,7 +18,7 @@
   
   from doctr.io import DocumentFile
   from doctr.models import ocr_predictor
  -from doctr.utils.visualization import synthetize_page, visualize_page
  +from doctr.utils.visualization import visualize_page
   
   DET_ARCHS = ["db_resnet50"]
   RECO_ARCHS = ["crnn_vgg16_bn", "master", "sar_resnet31"]
  @@ -96,7 +96,7 @@
   
                   # Page reconsitution under input page
                   page_export = out.pages[0].export()
  -                img = synthetize_page(page_export)
  +                img = out.pages[0].synthesize()
                   cols[3].image(img, clamp=True)
   
                   # Display JSON
  
verification_info: {"golden_diff": "diff --git a/demo/app.py b/demo/app.py\n--- a/demo/app.py\n+++ b/demo/app.py\n@@ -18,7 +18,7 @@\n \n from doctr.io import DocumentFile\n from doctr.models import ocr_predictor\n-from doctr.utils.visualization import synthetize_page, visualize_page\n+from doctr.utils.visualization import visualize_page\n \n DET_ARCHS = [\"db_resnet50\"]\n RECO_ARCHS = [\"crnn_vgg16_bn\", \"master\", \"sar_resnet31\"]\n@@ -96,7 +96,7 @@\n \n                 # Page reconsitution under input page\n                 page_export = out.pages[0].export()\n-                img = synthetize_page(page_export)\n+                img = out.pages[0].synthesize()\n                 cols[3].image(img, clamp=True)\n \n                 # Display JSON\n", "issue": "Import error synthetize_page func in streamlit demo script\n## \ud83d\udc1b Bug\r\n\r\nImport bug while running the streamlit demo script\r\n\r\n## To Reproduce\r\n\r\nSteps to reproduce the behavior:\r\n\r\n1. Install the current package version \r\n2. Run streamlit demo/app.py\r\n\r\nError message : ImportError: cannot import name 'synthetize_page' from 'doctr.utils.visualization' (/home/ubuntu/repos/mindee/doctr/doctr/utils/visualization.py)\r\n\r\n## Correction \r\n\r\nTry to import \"synthetize_page\" [from](https://github.com/mindee/doctr/blob/cfc329f8b21cd7d8c08d5c9190c53bd77a3149c4/doctr/utils/visualization.py#L19) whereas it should be \"synthesize_page\" [here](https://github.com/mindee/doctr/blob/cfc329f8b21cd7d8c08d5c9190c53bd77a3149c4/demo/app.py#L21) . It's probably a typo. It works after renaming.\n", "before_files": [{"content": "# Copyright (C) 2021, Mindee.\n\n# This program is licensed under the Apache License version 2.\n# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.\n\nimport os\nimport streamlit as st\nimport matplotlib.pyplot as plt\n\nos.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"2\"\n\nimport tensorflow as tf\nimport cv2\n\ngpu_devices = tf.config.experimental.list_physical_devices('GPU')\nif any(gpu_devices):\n    tf.config.experimental.set_memory_growth(gpu_devices[0], True)\n\nfrom doctr.io import DocumentFile\nfrom doctr.models import ocr_predictor\nfrom doctr.utils.visualization import synthetize_page, visualize_page\n\nDET_ARCHS = [\"db_resnet50\"]\nRECO_ARCHS = [\"crnn_vgg16_bn\", \"master\", \"sar_resnet31\"]\n\n\ndef main():\n\n    # Wide mode\n    st.set_page_config(layout=\"wide\")\n\n    # Designing the interface\n    st.title(\"DocTR: Document Text Recognition\")\n    # For newline\n    st.write('\\n')\n    # Instructions\n    st.markdown(\"*Hint: click on the top-right corner of an image to enlarge it!*\")\n    # Set the columns\n    cols = st.beta_columns((1, 1, 1, 1))\n    cols[0].subheader(\"Input page\")\n    cols[1].subheader(\"Segmentation heatmap\")\n    cols[2].subheader(\"OCR output\")\n    cols[3].subheader(\"Page reconstitution\")\n\n    # Sidebar\n    # File selection\n    st.sidebar.title(\"Document selection\")\n    # Disabling warning\n    st.set_option('deprecation.showfileUploaderEncoding', False)\n    # Choose your own image\n    uploaded_file = st.sidebar.file_uploader(\"Upload files\", type=['pdf', 'png', 'jpeg', 'jpg'])\n    if uploaded_file is not None:\n        if uploaded_file.name.endswith('.pdf'):\n            doc = DocumentFile.from_pdf(uploaded_file.read()).as_images()\n        else:\n            doc = DocumentFile.from_images(uploaded_file.read())\n        page_idx = st.sidebar.selectbox(\"Page selection\", [idx + 1 for idx in range(len(doc))]) - 1\n        cols[0].image(doc[page_idx])\n\n    # Model selection\n    st.sidebar.title(\"Model selection\")\n    det_arch = st.sidebar.selectbox(\"Text detection model\", DET_ARCHS)\n    reco_arch = st.sidebar.selectbox(\"Text recognition model\", RECO_ARCHS)\n\n    # For newline\n    st.sidebar.write('\\n')\n\n    if st.sidebar.button(\"Analyze page\"):\n\n        if uploaded_file is None:\n            st.sidebar.write(\"Please upload a document\")\n\n        else:\n            with st.spinner('Loading model...'):\n                predictor = ocr_predictor(det_arch, reco_arch, pretrained=True)\n\n            with st.spinner('Analyzing...'):\n\n                # Forward the image to the model\n                processed_batches = predictor.det_predictor.pre_processor([doc[page_idx]])\n                out = predictor.det_predictor.model(processed_batches[0], return_model_output=True, training=False)\n                seg_map = out[\"out_map\"]\n                seg_map = tf.squeeze(seg_map[0, ...], axis=[2])\n                seg_map = cv2.resize(seg_map.numpy(), (doc[page_idx].shape[1], doc[page_idx].shape[0]),\n                                     interpolation=cv2.INTER_LINEAR)\n                # Plot the raw heatmap\n                fig, ax = plt.subplots()\n                ax.imshow(seg_map)\n                ax.axis('off')\n                cols[1].pyplot(fig)\n\n                # Plot OCR output\n                out = predictor([doc[page_idx]], training=False)\n                fig = visualize_page(out.pages[0].export(), doc[page_idx], interactive=False)\n                cols[2].pyplot(fig)\n\n                # Page reconsitution under input page\n                page_export = out.pages[0].export()\n                img = synthetize_page(page_export)\n                cols[3].image(img, clamp=True)\n\n                # Display JSON\n                st.markdown(\"\\nHere are your analysis results in JSON format:\")\n                st.json(page_export)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "demo/app.py"}], "after_files": [{"content": "# Copyright (C) 2021, Mindee.\n\n# This program is licensed under the Apache License version 2.\n# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.\n\nimport os\nimport streamlit as st\nimport matplotlib.pyplot as plt\n\nos.environ[\"TF_CPP_MIN_LOG_LEVEL\"] = \"2\"\n\nimport tensorflow as tf\nimport cv2\n\ngpu_devices = tf.config.experimental.list_physical_devices('GPU')\nif any(gpu_devices):\n    tf.config.experimental.set_memory_growth(gpu_devices[0], True)\n\nfrom doctr.io import DocumentFile\nfrom doctr.models import ocr_predictor\nfrom doctr.utils.visualization import visualize_page\n\nDET_ARCHS = [\"db_resnet50\"]\nRECO_ARCHS = [\"crnn_vgg16_bn\", \"master\", \"sar_resnet31\"]\n\n\ndef main():\n\n    # Wide mode\n    st.set_page_config(layout=\"wide\")\n\n    # Designing the interface\n    st.title(\"DocTR: Document Text Recognition\")\n    # For newline\n    st.write('\\n')\n    # Instructions\n    st.markdown(\"*Hint: click on the top-right corner of an image to enlarge it!*\")\n    # Set the columns\n    cols = st.beta_columns((1, 1, 1, 1))\n    cols[0].subheader(\"Input page\")\n    cols[1].subheader(\"Segmentation heatmap\")\n    cols[2].subheader(\"OCR output\")\n    cols[3].subheader(\"Page reconstitution\")\n\n    # Sidebar\n    # File selection\n    st.sidebar.title(\"Document selection\")\n    # Disabling warning\n    st.set_option('deprecation.showfileUploaderEncoding', False)\n    # Choose your own image\n    uploaded_file = st.sidebar.file_uploader(\"Upload files\", type=['pdf', 'png', 'jpeg', 'jpg'])\n    if uploaded_file is not None:\n        if uploaded_file.name.endswith('.pdf'):\n            doc = DocumentFile.from_pdf(uploaded_file.read()).as_images()\n        else:\n            doc = DocumentFile.from_images(uploaded_file.read())\n        page_idx = st.sidebar.selectbox(\"Page selection\", [idx + 1 for idx in range(len(doc))]) - 1\n        cols[0].image(doc[page_idx])\n\n    # Model selection\n    st.sidebar.title(\"Model selection\")\n    det_arch = st.sidebar.selectbox(\"Text detection model\", DET_ARCHS)\n    reco_arch = st.sidebar.selectbox(\"Text recognition model\", RECO_ARCHS)\n\n    # For newline\n    st.sidebar.write('\\n')\n\n    if st.sidebar.button(\"Analyze page\"):\n\n        if uploaded_file is None:\n            st.sidebar.write(\"Please upload a document\")\n\n        else:\n            with st.spinner('Loading model...'):\n                predictor = ocr_predictor(det_arch, reco_arch, pretrained=True)\n\n            with st.spinner('Analyzing...'):\n\n                # Forward the image to the model\n                processed_batches = predictor.det_predictor.pre_processor([doc[page_idx]])\n                out = predictor.det_predictor.model(processed_batches[0], return_model_output=True, training=False)\n                seg_map = out[\"out_map\"]\n                seg_map = tf.squeeze(seg_map[0, ...], axis=[2])\n                seg_map = cv2.resize(seg_map.numpy(), (doc[page_idx].shape[1], doc[page_idx].shape[0]),\n                                     interpolation=cv2.INTER_LINEAR)\n                # Plot the raw heatmap\n                fig, ax = plt.subplots()\n                ax.imshow(seg_map)\n                ax.axis('off')\n                cols[1].pyplot(fig)\n\n                # Plot OCR output\n                out = predictor([doc[page_idx]], training=False)\n                fig = visualize_page(out.pages[0].export(), doc[page_idx], interactive=False)\n                cols[2].pyplot(fig)\n\n                # Page reconsitution under input page\n                page_export = out.pages[0].export()\n                img = out.pages[0].synthesize()\n                cols[3].image(img, clamp=True)\n\n                # Display JSON\n                st.markdown(\"\\nHere are your analysis results in JSON format:\")\n                st.json(page_export)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "demo/app.py"}]}