Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import base64
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
# Example DataFrame
|
5 |
+
data = {'Column1': [1, 2], 'Column2': [3, 4]}
|
6 |
+
df = pd.DataFrame(data)
|
7 |
+
|
8 |
+
# Function to convert DataFrame to CSV and then encode to base64
|
9 |
+
def to_base64_csv(df):
|
10 |
+
csv = df.to_csv(index=False)
|
11 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
12 |
+
return f"data:text/csv;base64,{b64}"
|
13 |
+
|
14 |
+
# Function to convert DataFrame to TXT and then encode to base64
|
15 |
+
def to_base64_txt(df):
|
16 |
+
txt = df.to_csv(index=False, sep='\t')
|
17 |
+
b64 = base64.b64encode(txt.encode()).decode()
|
18 |
+
return f"data:text/plain;base64,{b64}"
|
19 |
+
|
20 |
+
# Generate base64 encoded links
|
21 |
+
csv_link = to_base64_csv(df)
|
22 |
+
txt_link = to_base64_txt(df)
|
23 |
+
|
24 |
+
# Markdown format for hyperlinks in bold font with emojis
|
25 |
+
markdown_csv_link = f"**[📥 Download Dataset as CSV]({csv_link})**"
|
26 |
+
markdown_txt_link = f"**[📥 Download Dataset as TXT]({txt_link})**"
|
27 |
+
|
28 |
+
# Display as markdown (hypothetical, depends on how you render markdown in your application)
|
29 |
+
print(markdown_csv_link)
|
30 |
+
print(markdown_txt_link)
|