Shaltiel commited on
Commit
15d2ecf
1 Parent(s): 1ae6640

Added download button

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import base64
3
  from transformers import AutoModel, AutoTokenizer
@@ -40,7 +41,14 @@ def display_tree(output):
40
  """, unsafe_allow_html=True)
41
 
42
  #st.image('syntax_tree.' + format, use_column_width=True)
43
-
 
 
 
 
 
 
 
44
  # Streamlit app title
45
  st.title('DictaBERT-Joint Visualizer')
46
 
@@ -80,6 +88,8 @@ if sentence:
80
  tree.append(dict(word=parts[1], dep_head_idx=int(parts[6]) - 1, dep_func=parts[7]))
81
  display_tree(tree)
82
 
 
 
83
  # Construct the table as a Markdown string
84
  table_md = "<div dir='rtl' style='text-align: right;'>\n\n" # Start with RTL div
85
 
@@ -105,7 +115,10 @@ if sentence:
105
  tree = [w['syntax'] for w in output['tokens']]
106
  display_tree(tree)
107
 
 
 
 
108
  # and the full json
109
- st.markdown("```json\n" + json.dumps(output, ensure_ascii=False, indent=2) + "\n```")
110
 
111
 
 
1
+ from io import BytesIO
2
  import streamlit as st
3
  import base64
4
  from transformers import AutoModel, AutoTokenizer
 
41
  """, unsafe_allow_html=True)
42
 
43
  #st.image('syntax_tree.' + format, use_column_width=True)
44
+
45
+ def display_download(disp_string):
46
+ to_download = BytesIO(disp_string.encode())
47
+ st.download_button(label="⬇️ Download text file",
48
+ data=to_download,
49
+ file_name="parsed_output.txt",
50
+ mime="text/plain")
51
+
52
  # Streamlit app title
53
  st.title('DictaBERT-Joint Visualizer')
54
 
 
88
  tree.append(dict(word=parts[1], dep_head_idx=int(parts[6]) - 1, dep_func=parts[7]))
89
  display_tree(tree)
90
 
91
+ display_download('\n'.join(ud_output))
92
+
93
  # Construct the table as a Markdown string
94
  table_md = "<div dir='rtl' style='text-align: right;'>\n\n" # Start with RTL div
95
 
 
115
  tree = [w['syntax'] for w in output['tokens']]
116
  display_tree(tree)
117
 
118
+ json_output = json.dumps(output, ensure_ascii=False, indent=2)
119
+ display_download(json_output)
120
+
121
  # and the full json
122
+ st.markdown("```json\n" + json_output + "\n```")
123
 
124