Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -134,20 +134,13 @@ def show_violin_plot(df):
|
|
| 134 |
},
|
| 135 |
}
|
| 136 |
|
| 137 |
-
import streamlit as st
|
| 138 |
-
|
| 139 |
-
# Predefined analysis tasks and visualization types
|
| 140 |
-
PREDEFINED_ANALYSIS = {
|
| 141 |
-
# ... (Predefined analysis tasks remain the same)
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
def generate_streamlit_app_code(app_title, app_subtitle, side_panel_title, analysis_tasks, requirements):
|
| 145 |
# Generate Python code for the Streamlit app
|
| 146 |
# Here we make sure the analysis functions are correctly indented at the same level as the main function
|
| 147 |
analysis_functions_code = "\n ".join([PREDEFINED_ANALYSIS[task]['Code'].replace("\n", "\n ") for task in analysis_tasks])
|
| 148 |
# Here we ensure that calls to analysis functions are correctly indented within the main function
|
| 149 |
analysis_tasks_code = "\n".join([f" {PREDEFINED_ANALYSIS[task]['Function']}(df)" for task in analysis_tasks])
|
| 150 |
-
|
| 151 |
code = f"""import streamlit as st
|
| 152 |
import pandas as pd
|
| 153 |
import seaborn as sns
|
|
@@ -164,21 +157,20 @@ def main():
|
|
| 164 |
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
| 165 |
|
| 166 |
if uploaded_file is not None:
|
| 167 |
-
@st.
|
| 168 |
def load_data(uploaded_file):
|
| 169 |
return pd.read_csv(uploaded_file)
|
| 170 |
|
| 171 |
df = load_data(uploaded_file)
|
| 172 |
|
| 173 |
{analysis_functions_code}
|
| 174 |
-
|
| 175 |
# Analysis task calls
|
| 176 |
{analysis_tasks_code}
|
| 177 |
except Exception as e:
|
| 178 |
st.error(f"An error occurred: {str(e)}")
|
| 179 |
|
| 180 |
-
|
| 181 |
-
main()
|
| 182 |
"""
|
| 183 |
return code
|
| 184 |
|
|
@@ -211,7 +203,7 @@ def main():
|
|
| 211 |
# Download the generated files
|
| 212 |
with open(file_path, "rb") as file:
|
| 213 |
btn = st.download_button(label="Download your Streamlit app", data=file, file_name=file_path)
|
| 214 |
-
|
| 215 |
if requirements:
|
| 216 |
with open("requirements.txt", "rb") as req_file:
|
| 217 |
btn_req = st.download_button(label="Download requirements.txt", data=req_file, file_name="requirements.txt")
|
|
@@ -219,4 +211,4 @@ def main():
|
|
| 219 |
st.warning("Please enter a title for your Streamlit app.")
|
| 220 |
|
| 221 |
if __name__ == "__main__":
|
| 222 |
-
main()
|
|
|
|
| 134 |
},
|
| 135 |
}
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
def generate_streamlit_app_code(app_title, app_subtitle, side_panel_title, analysis_tasks, requirements):
|
| 138 |
# Generate Python code for the Streamlit app
|
| 139 |
# Here we make sure the analysis functions are correctly indented at the same level as the main function
|
| 140 |
analysis_functions_code = "\n ".join([PREDEFINED_ANALYSIS[task]['Code'].replace("\n", "\n ") for task in analysis_tasks])
|
| 141 |
# Here we ensure that calls to analysis functions are correctly indented within the main function
|
| 142 |
analysis_tasks_code = "\n".join([f" {PREDEFINED_ANALYSIS[task]['Function']}(df)" for task in analysis_tasks])
|
| 143 |
+
|
| 144 |
code = f"""import streamlit as st
|
| 145 |
import pandas as pd
|
| 146 |
import seaborn as sns
|
|
|
|
| 157 |
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
| 158 |
|
| 159 |
if uploaded_file is not None:
|
| 160 |
+
@st.cache
|
| 161 |
def load_data(uploaded_file):
|
| 162 |
return pd.read_csv(uploaded_file)
|
| 163 |
|
| 164 |
df = load_data(uploaded_file)
|
| 165 |
|
| 166 |
{analysis_functions_code}
|
| 167 |
+
|
| 168 |
# Analysis task calls
|
| 169 |
{analysis_tasks_code}
|
| 170 |
except Exception as e:
|
| 171 |
st.error(f"An error occurred: {str(e)}")
|
| 172 |
|
| 173 |
+
main()
|
|
|
|
| 174 |
"""
|
| 175 |
return code
|
| 176 |
|
|
|
|
| 203 |
# Download the generated files
|
| 204 |
with open(file_path, "rb") as file:
|
| 205 |
btn = st.download_button(label="Download your Streamlit app", data=file, file_name=file_path)
|
| 206 |
+
|
| 207 |
if requirements:
|
| 208 |
with open("requirements.txt", "rb") as req_file:
|
| 209 |
btn_req = st.download_button(label="Download requirements.txt", data=req_file, file_name="requirements.txt")
|
|
|
|
| 211 |
st.warning("Please enter a title for your Streamlit app.")
|
| 212 |
|
| 213 |
if __name__ == "__main__":
|
| 214 |
+
main()
|