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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -139,7 +139,7 @@ def generate_streamlit_app_code(app_title, app_subtitle, side_panel_title, analy
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
  # The exception handling block has been removed as per your request
145
  code = f"""import streamlit as st
@@ -156,8 +156,10 @@ def main():
156
 
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
 
@@ -165,7 +167,7 @@ def main():
165
 
166
  {analysis_functions_code}
167
 
168
- # Analysis task calls
169
  {analysis_tasks_code}
170
 
171
  if __name__ == "__main__":
@@ -173,6 +175,7 @@ if __name__ == "__main__":
173
  """
174
  return code
175
 
 
176
  def main():
177
  st.title("Streamlit App Generator")
178
 
 
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
 
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
 
 
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__":
 
175
  """
176
  return code
177
 
178
+
179
  def main():
180
  st.title("Streamlit App Generator")
181