Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,10 +18,10 @@ st.set_page_config(
|
|
18 |
layout="wide")
|
19 |
|
20 |
menu = ["txt", "htm", "md", "py"]
|
21 |
-
choice = st.sidebar.selectbox("
|
22 |
-
choicePrefix = "Output
|
23 |
if choice == "txt":
|
24 |
-
st.sidebar.write(choicePrefix + "Text
|
25 |
elif choice == "htm":
|
26 |
st.sidebar.write(choicePrefix + "HTML5.")
|
27 |
elif choice == "md":
|
@@ -66,14 +66,11 @@ def get_table_download_link_old(file_path):
|
|
66 |
return href
|
67 |
|
68 |
def get_table_download_link(file_path):
|
69 |
-
import os
|
70 |
-
import base64
|
71 |
with open(file_path, 'r') as file:
|
72 |
data = file.read()
|
73 |
b64 = base64.b64encode(data.encode()).decode()
|
74 |
file_name = os.path.basename(file_path)
|
75 |
ext = os.path.splitext(file_name)[1] # get the file extension
|
76 |
-
|
77 |
if ext == '.txt':
|
78 |
mime_type = 'text/plain'
|
79 |
elif ext == '.htm':
|
@@ -82,7 +79,6 @@ def get_table_download_link(file_path):
|
|
82 |
mime_type = 'text/markdown'
|
83 |
else:
|
84 |
mime_type = 'application/octet-stream' # general binary data type
|
85 |
-
|
86 |
href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
|
87 |
return href
|
88 |
|
|
|
18 |
layout="wide")
|
19 |
|
20 |
menu = ["txt", "htm", "md", "py"]
|
21 |
+
choice = st.sidebar.selectbox("Output file type:", menu)
|
22 |
+
choicePrefix = "Output file type is "
|
23 |
if choice == "txt":
|
24 |
+
st.sidebar.write(choicePrefix + "Text File.")
|
25 |
elif choice == "htm":
|
26 |
st.sidebar.write(choicePrefix + "HTML5.")
|
27 |
elif choice == "md":
|
|
|
66 |
return href
|
67 |
|
68 |
def get_table_download_link(file_path):
|
|
|
|
|
69 |
with open(file_path, 'r') as file:
|
70 |
data = file.read()
|
71 |
b64 = base64.b64encode(data.encode()).decode()
|
72 |
file_name = os.path.basename(file_path)
|
73 |
ext = os.path.splitext(file_name)[1] # get the file extension
|
|
|
74 |
if ext == '.txt':
|
75 |
mime_type = 'text/plain'
|
76 |
elif ext == '.htm':
|
|
|
79 |
mime_type = 'text/markdown'
|
80 |
else:
|
81 |
mime_type = 'application/octet-stream' # general binary data type
|
|
|
82 |
href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
|
83 |
return href
|
84 |
|