deepsh2207 commited on
Commit
63f1335
·
1 Parent(s): d840e96

corrected dowload behaviour

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -4,6 +4,7 @@ import numpy as np
4
  import streamlit as st
5
  import torch
6
  import json
 
7
 
8
  from doctr.io import DocumentFile
9
  from doctr.utils.visualization import visualize_page
@@ -116,13 +117,16 @@ def main(det_archs, reco_archs):
116
  print('\n')
117
 
118
  # Display Text
119
- st.markdown("\n## **Here is your text:**")
120
  st.write(all_text)
121
 
122
  # Display JSON
123
- json_string = json.dumps(page_export)
124
- st.markdown("\n## **Here are your analysis results in JSON format:**")
125
- st.download_button(label="Download JSON", data=json_string, file_name='data.json', mime='application/json')
 
 
 
126
  st.json(page_export, expanded=False)
127
 
128
 
 
4
  import streamlit as st
5
  import torch
6
  import json
7
+ import base64
8
 
9
  from doctr.io import DocumentFile
10
  from doctr.utils.visualization import visualize_page
 
117
  print('\n')
118
 
119
  # Display Text
120
+ st.markdown("\n### **Here is your text:**")
121
  st.write(all_text)
122
 
123
  # Display JSON
124
+ # json_string = json.dumps(page_export)
125
+ st.markdown("\n### **Here is your document structure in JSON format:**")
126
+ encoded_data = base64.b64encode(json.dumps(page_export).encode("utf-8")).decode("utf-8")
127
+ download_link = f"data:application/json;base64,{encoded_data}"
128
+ st.markdown(f"[Download JSON]( {download_link} )")
129
+ # st.download_button(label="Download JSON", data=json_string, file_name='data.json', mime='application/json')
130
  st.json(page_export, expanded=False)
131
 
132