Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -136,12 +136,12 @@ def show_violin_plot(df):
|
|
| 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 |
-
#
|
| 140 |
analysis_functions_code = "\n ".join([PREDEFINED_ANALYSIS[task]['Code'].replace("\n", "\n ") for task in analysis_tasks])
|
| 141 |
-
#
|
| 142 |
-
analysis_tasks_code = "
|
| 143 |
|
| 144 |
-
#
|
| 145 |
code = f"""import streamlit as st
|
| 146 |
import pandas as pd
|
| 147 |
import seaborn as sns
|
|
@@ -155,23 +155,20 @@ def main():
|
|
| 155 |
st.sidebar.title("{side_panel_title}")
|
| 156 |
|
| 157 |
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
| 158 |
-
|
| 159 |
df = pd.DataFrame() # Initialize an empty DataFrame
|
| 160 |
|
| 161 |
if uploaded_file is not None:
|
| 162 |
-
@st.
|
| 163 |
def load_data(uploaded_file):
|
| 164 |
return pd.read_csv(uploaded_file)
|
| 165 |
-
|
| 166 |
df = load_data(uploaded_file)
|
| 167 |
|
| 168 |
{analysis_functions_code}
|
| 169 |
-
|
| 170 |
-
|
| 171 |
{analysis_tasks_code}
|
| 172 |
|
| 173 |
-
|
| 174 |
-
main()
|
| 175 |
"""
|
| 176 |
return code
|
| 177 |
|
|
|
|
| 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 |
+
# Ensure 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 |
+
# Ensure calls to analysis functions are correctly indented within the main function and only executed if df is not empty
|
| 142 |
+
analysis_tasks_code = " if not df.empty:\n" + "\n".join([f" {PREDEFINED_ANALYSIS[task]['Function']}(df)" for task in analysis_tasks])
|
| 143 |
|
| 144 |
+
# Generate the full code for the Streamlit app
|
| 145 |
code = f"""import streamlit as st
|
| 146 |
import pandas as pd
|
| 147 |
import seaborn as sns
|
|
|
|
| 155 |
st.sidebar.title("{side_panel_title}")
|
| 156 |
|
| 157 |
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
|
|
|
|
| 158 |
df = pd.DataFrame() # Initialize an empty DataFrame
|
| 159 |
|
| 160 |
if uploaded_file is not None:
|
| 161 |
+
@st.cache # Use the correct caching decorator
|
| 162 |
def load_data(uploaded_file):
|
| 163 |
return pd.read_csv(uploaded_file)
|
|
|
|
| 164 |
df = load_data(uploaded_file)
|
| 165 |
|
| 166 |
{analysis_functions_code}
|
| 167 |
+
|
| 168 |
+
# Analysis task calls, only executed if df is not empty
|
| 169 |
{analysis_tasks_code}
|
| 170 |
|
| 171 |
+
main() # Call the main function to run the app
|
|
|
|
| 172 |
"""
|
| 173 |
return code
|
| 174 |
|