yashm commited on
Commit
370c8ad
·
verified ·
1 Parent(s): cebaf1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
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
- # 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 if not df.empty:\n" + "\n".join([f" {PREDEFINED_ANALYSIS[task]['Function']}(df)" for task in analysis_tasks])
143
 
144
- # The exception handling block has been removed as per your request
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.cache_data # Correct the caching decorator
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
- # Analysis task calls, only executed if df is not empty
171
  {analysis_tasks_code}
172
 
173
- if __name__ == "__main__":
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