Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -153,14 +153,39 @@ st.text("")
|
|
| 153 |
st.table(df)
|
| 154 |
st.text("")
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
|
|
|
|
|
|
|
|
|
| 163 |
|
|
|
|
|
|
|
| 164 |
#-----------------------------------------------------------------------
|
| 165 |
|
| 166 |
import streamlit as st
|
|
|
|
| 153 |
st.table(df)
|
| 154 |
st.text("")
|
| 155 |
|
| 156 |
+
import base64
|
| 157 |
+
import pandas as pd
|
| 158 |
+
|
| 159 |
+
# Example DataFrame
|
| 160 |
+
data = {'Column1': [1, 2], 'Column2': [3, 4]}
|
| 161 |
+
df = pd.DataFrame(data)
|
| 162 |
+
|
| 163 |
+
# Function to convert DataFrame to CSV and then encode to base64
|
| 164 |
+
def to_base64_csv(df):
|
| 165 |
+
csv = df.to_csv(index=False)
|
| 166 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
| 167 |
+
return f"data:text/csv;base64,{b64}"
|
| 168 |
+
|
| 169 |
+
# Function to convert DataFrame to TXT and then encode to base64
|
| 170 |
+
def to_base64_txt(df):
|
| 171 |
+
txt = df.to_csv(index=False, sep='\t')
|
| 172 |
+
b64 = base64.b64encode(txt.encode()).decode()
|
| 173 |
+
return f"data:text/plain;base64,{b64}"
|
| 174 |
+
|
| 175 |
+
# Generate base64 encoded links
|
| 176 |
+
csv_link = to_base64_csv(df)
|
| 177 |
+
txt_link = to_base64_txt(df)
|
| 178 |
+
|
| 179 |
+
# Markdown format for hyperlinks in bold font with emojis
|
| 180 |
+
markdown_csv_link = f"**[📥 Download Dataset as CSV]({csv_link})**"
|
| 181 |
+
markdown_txt_link = f"**[📥 Download Dataset as TXT]({txt_link})**"
|
| 182 |
|
| 183 |
+
# Display as markdown (hypothetical, depends on how you render markdown in your application)
|
| 184 |
+
print(markdown_csv_link)
|
| 185 |
+
print(markdown_txt_link)
|
| 186 |
|
| 187 |
+
st.markdown(markdown_csv_link, unsafe_allow_html=True)
|
| 188 |
+
st.markdown(markdown_txt_link, unsafe_allow_html=True)
|
| 189 |
#-----------------------------------------------------------------------
|
| 190 |
|
| 191 |
import streamlit as st
|