Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -173,6 +173,37 @@ main() # Call the main function to run the app
|
|
| 173 |
return code
|
| 174 |
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
def main():
|
| 177 |
st.title("Streamlit App Generator")
|
| 178 |
|
|
@@ -184,8 +215,9 @@ def main():
|
|
| 184 |
# Select predefined analysis tasks
|
| 185 |
selected_tasks = st.multiselect("Select predefined analysis tasks to include:", list(PREDEFINED_ANALYSIS.keys()))
|
| 186 |
|
| 187 |
-
#
|
| 188 |
-
|
|
|
|
| 189 |
|
| 190 |
if st.button("Generate and Download"):
|
| 191 |
if app_title:
|
|
@@ -195,17 +227,15 @@ def main():
|
|
| 195 |
f.write(generate_streamlit_app_code(app_title, app_subtitle, side_panel_title, selected_tasks, requirements))
|
| 196 |
|
| 197 |
# Write requirements.txt file
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
req_file.write(requirements)
|
| 201 |
|
| 202 |
# Download the generated files
|
| 203 |
with open(file_path, "rb") as file:
|
| 204 |
btn = st.download_button(label="Download your Streamlit app", data=file, file_name=file_path)
|
| 205 |
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
btn_req = st.download_button(label="Download requirements.txt", data=req_file, file_name="requirements.txt")
|
| 209 |
else:
|
| 210 |
st.warning("Please enter a title for your Streamlit app.")
|
| 211 |
|
|
|
|
| 173 |
return code
|
| 174 |
|
| 175 |
|
| 176 |
+
# Define required libraries for each predefined analysis task
|
| 177 |
+
TASK_REQUIREMENTS = {
|
| 178 |
+
"Basic Statistics": ["pandas", "streamlit"],
|
| 179 |
+
"Correlation Heatmap": ["pandas", "streamlit", "seaborn"],
|
| 180 |
+
"Histogram": ["pandas", "streamlit", "plotly"],
|
| 181 |
+
"Box Plot": ["pandas", "streamlit", "plotly"],
|
| 182 |
+
"Scatter Plot": ["pandas", "streamlit", "plotly"],
|
| 183 |
+
"Line Plot": ["pandas", "streamlit", "plotly"],
|
| 184 |
+
"Bar Chart": ["pandas", "streamlit", "plotly"],
|
| 185 |
+
"Pair Plot": ["pandas", "streamlit", "seaborn"],
|
| 186 |
+
"Distribution Plot": ["pandas", "streamlit", "seaborn"],
|
| 187 |
+
"Count Plot": ["pandas", "streamlit", "seaborn"],
|
| 188 |
+
"Pie Chart": ["pandas", "streamlit", "plotly"],
|
| 189 |
+
"Area Plot": ["pandas", "streamlit", "plotly"],
|
| 190 |
+
"Violin Plot": ["pandas", "streamlit", "plotly"]
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
def generate_requirements(selected_tasks):
|
| 194 |
+
# Set to store all unique required libraries
|
| 195 |
+
required_libraries = set()
|
| 196 |
+
|
| 197 |
+
# Add libraries for each selected task
|
| 198 |
+
for task in selected_tasks:
|
| 199 |
+
required_libraries.update(TASK_REQUIREMENTS.get(task, []))
|
| 200 |
+
|
| 201 |
+
# Convert set to sorted list for consistent order
|
| 202 |
+
requirements_list = sorted(list(required_libraries))
|
| 203 |
+
|
| 204 |
+
# Format list into string to place in requirements.txt format
|
| 205 |
+
return "\n".join(requirements_list)
|
| 206 |
+
|
| 207 |
def main():
|
| 208 |
st.title("Streamlit App Generator")
|
| 209 |
|
|
|
|
| 215 |
# Select predefined analysis tasks
|
| 216 |
selected_tasks = st.multiselect("Select predefined analysis tasks to include:", list(PREDEFINED_ANALYSIS.keys()))
|
| 217 |
|
| 218 |
+
# Automatically generate requirements.txt content based on selected tasks
|
| 219 |
+
auto_requirements = generate_requirements(selected_tasks)
|
| 220 |
+
requirements = st.text_area("Enter requirements.txt content (optional):", value=auto_requirements)
|
| 221 |
|
| 222 |
if st.button("Generate and Download"):
|
| 223 |
if app_title:
|
|
|
|
| 227 |
f.write(generate_streamlit_app_code(app_title, app_subtitle, side_panel_title, selected_tasks, requirements))
|
| 228 |
|
| 229 |
# Write requirements.txt file
|
| 230 |
+
with open("requirements.txt", "w") as req_file:
|
| 231 |
+
req_file.write(requirements)
|
|
|
|
| 232 |
|
| 233 |
# Download the generated files
|
| 234 |
with open(file_path, "rb") as file:
|
| 235 |
btn = st.download_button(label="Download your Streamlit app", data=file, file_name=file_path)
|
| 236 |
|
| 237 |
+
with open("requirements.txt", "rb") as req_file:
|
| 238 |
+
btn_req = st.download_button(label="Download requirements.txt", data=req_file, file_name="requirements.txt")
|
|
|
|
| 239 |
else:
|
| 240 |
st.warning("Please enter a title for your Streamlit app.")
|
| 241 |
|