Ninad077 commited on
Commit
d2205dc
·
verified ·
1 Parent(s): b6f51d6

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -28
app.py CHANGED
@@ -36,19 +36,13 @@ h1 {
36
  # Set up the Streamlit app
37
  st.markdown(styles, unsafe_allow_html=True)
38
 
39
- # Set up the Streamlit app
40
- st.markdown(styles, unsafe_allow_html=True)
41
-
42
  # Custom gradient title
43
  st.markdown("<h1>CSV appender</h1>", unsafe_allow_html=True)
44
- st.write("A website that is used for appending multiple csv files and converting them to excel format")
45
 
46
  # File uploader for multiple CSV files
47
  uploaded_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True)
48
 
49
- # Render the button styles
50
- st.markdown(styles, unsafe_allow_html=True)
51
-
52
  if uploaded_files:
53
  # Initialize an empty list to store DataFrames
54
  df_list = []
@@ -77,12 +71,42 @@ if uploaded_files:
77
 
78
  with col1:
79
  # Provide a download button for the merged CSV file
80
- if st.button("Append CSV"):
81
- csv_output = BytesIO()
82
- merged_df.to_csv(csv_output, index=False)
83
- csv_output.seek(0)
84
- csv_base64 = base64.b64encode(csv_output.getvalue()).decode()
85
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  with col2:
88
  # Provide an option to convert to Excel
@@ -92,20 +116,36 @@ if uploaded_files:
92
  merged_df.to_excel(writer, index=False)
93
  excel_output.seek(0)
94
 
95
- # Store the Excel output in session state for later download
96
- excel_base64 = base64.b64encode(excel_output.getvalue()).decode()
97
- st.session_state.excel_data = excel_base64
98
- st.session_state.excel_ready = True
99
-
100
- with col3:
101
- # Provide a download button for the Excel file if it has been converted
102
- if st.button("Download excel"):
103
- if st.session_state.get("excel_ready", False):
104
- st.markdown(f"""
105
- <a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{st.session_state.excel_data}" download="merged_data.xlsx" class="stButton">
106
- <button>Download excel</button>
107
- </a>
108
- """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  else:
111
- st.write("")
 
36
  # Set up the Streamlit app
37
  st.markdown(styles, unsafe_allow_html=True)
38
 
 
 
 
39
  # Custom gradient title
40
  st.markdown("<h1>CSV appender</h1>", unsafe_allow_html=True)
41
+ st.write("A website that is used for appending multiple CSV files and converting them to Excel format")
42
 
43
  # File uploader for multiple CSV files
44
  uploaded_files = st.file_uploader("Upload CSV files", type="csv", accept_multiple_files=True)
45
 
 
 
 
46
  if uploaded_files:
47
  # Initialize an empty list to store DataFrames
48
  df_list = []
 
71
 
72
  with col1:
73
  # Provide a download button for the merged CSV file
74
+ if st.button("Convert to CSV"):
75
+ csv_output = BytesIO()
76
+ merged_df.to_csv(csv_output, index=False)
77
+ csv_output.seek(0)
78
+
79
+ # Define CSS styles for the button
80
+ button_styles = """
81
+ <style>
82
+ div.stButton > button {
83
+ color: #ffffff; /* Text color */
84
+ font-size: 50px;
85
+ background-image: linear-gradient(0deg, #a689f6 3%, #413bb9 61%);
86
+ border: none;
87
+ padding: 10px 20px;
88
+ cursor: pointer;
89
+ border-radius: 15px;
90
+ display: inline-block;
91
+ }
92
+ div.stButton > button:hover {
93
+ background-color: #00ff00; /* Hover background color */
94
+ color: #ff0000; /* Hover text color */
95
+ }
96
+ </style>
97
+ """
98
+
99
+ # Render the button with the specified styles
100
+ st.markdown(button_styles, unsafe_allow_html=True)
101
+
102
+
103
+
104
+ st.download_button(
105
+ label="Download Merged CSV File",
106
+ data=csv_output,
107
+ file_name="merged_data.csv",
108
+ mime="text/csv"
109
+ )
110
 
111
  with col2:
112
  # Provide an option to convert to Excel
 
116
  merged_df.to_excel(writer, index=False)
117
  excel_output.seek(0)
118
 
119
+ # Define CSS styles for the button
120
+ button_styles = """
121
+ <style>
122
+ div.stButton > button {
123
+ color: #ffffff; /* Text color */
124
+ font-size: 50px;
125
+ background-image: linear-gradient(0deg, #a689f6 3%, #413bb9 61%);
126
+ border: none;
127
+ padding: 10px 20px;
128
+ cursor: pointer;
129
+ border-radius: 15px;
130
+ display: inline-block;
131
+ }
132
+ div.stButton > button:hover {
133
+ background-color: #00ff00; /* Hover background color */
134
+ color: #ff0000; /* Hover text color */
135
+ }
136
+ </style>
137
+ """
138
+
139
+ # Render the button with the specified styles
140
+ st.markdown(button_styles, unsafe_allow_html=True)
141
+
142
+ # Provide a download button for the Excel file
143
+ st.download_button(
144
+ label="Download Excel",
145
+ data=excel_output,
146
+ file_name="merged_data.xlsx",
147
+ mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
148
+ )
149
 
150
  else:
151
+ st.write(" ")