yashm commited on
Commit
c3bbdce
·
verified ·
1 Parent(s): 27facfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -3,13 +3,13 @@ import os
3
 
4
  # Predefined code snippets for common components
5
  PREDEFINED_COMPONENTS = {
6
- "Title": "st.title('Your Title Here')",
7
- "Subtitle": "st.subheader('Your Subtitle Here')",
8
- "Side Panel": "st.sidebar.title('Sidebar Title')",
9
  # Add more predefined components as needed
10
  }
11
 
12
- def generate_streamlit_app_code(app_title, app_content, requirements):
13
  # Generate Python code for the Streamlit app
14
  code = f"""
15
  import streamlit as st
@@ -18,6 +18,8 @@ import streamlit as st
18
 
19
  def main():
20
  st.title("{app_title}")
 
 
21
  {app_content}
22
 
23
  if __name__ == "__main__":
@@ -28,7 +30,12 @@ if __name__ == "__main__":
28
  def main():
29
  st.title("Streamlit App Generator")
30
 
 
31
  app_title = st.text_input("Enter your Streamlit app title:")
 
 
 
 
32
  app_content = st.text_area("Enter your Streamlit app content (Python code):")
33
 
34
  # Include predefined components
@@ -37,8 +44,11 @@ def main():
37
  # Generate requirements.txt file
38
  requirements = st.text_area("Enter requirements.txt content (optional):")
39
 
 
 
 
40
  if st.button("Generate and Download"):
41
- if app_title and app_content:
42
  # Include selected predefined components in the app content
43
  for component in selected_components:
44
  app_content += f"\n{PREDEFINED_COMPONENTS[component]}"
@@ -46,7 +56,7 @@ def main():
46
  # Write generated code to a .py file
47
  file_path = f"{app_title.replace(' ', '_').lower()}_app.py"
48
  with open(file_path, "w") as f:
49
- f.write(generate_streamlit_app_code(app_title, app_content, requirements))
50
 
51
  # Write requirements.txt file
52
  if requirements:
@@ -61,7 +71,7 @@ def main():
61
  with open("requirements.txt", "rb") as req_file:
62
  btn_req = st.download_button(label="Download requirements.txt", data=req_file, file_name="requirements.txt")
63
  else:
64
- st.warning("Please enter a title and content for your Streamlit app.")
65
 
66
  if __name__ == "__main__":
67
  main()
 
3
 
4
  # Predefined code snippets for common components
5
  PREDEFINED_COMPONENTS = {
6
+ "Title": "st.title(app_title)",
7
+ "Subtitle": "st.subheader(app_subtitle)",
8
+ "Side Panel": "st.sidebar.title(side_panel_title)",
9
  # Add more predefined components as needed
10
  }
11
 
12
+ def generate_streamlit_app_code(app_title, app_subtitle, side_panel_title, app_content, requirements):
13
  # Generate Python code for the Streamlit app
14
  code = f"""
15
  import streamlit as st
 
18
 
19
  def main():
20
  st.title("{app_title}")
21
+ st.subheader("{app_subtitle}")
22
+ st.sidebar.title("{side_panel_title}")
23
  {app_content}
24
 
25
  if __name__ == "__main__":
 
30
  def main():
31
  st.title("Streamlit App Generator")
32
 
33
+ # User inputs for app parameters
34
  app_title = st.text_input("Enter your Streamlit app title:")
35
+ app_subtitle = st.text_input("Enter your Streamlit app subtitle:")
36
+ side_panel_title = st.text_input("Enter your Streamlit app side panel title:")
37
+
38
+ # Input for Streamlit app content
39
  app_content = st.text_area("Enter your Streamlit app content (Python code):")
40
 
41
  # Include predefined components
 
44
  # Generate requirements.txt file
45
  requirements = st.text_area("Enter requirements.txt content (optional):")
46
 
47
+ # File uploader for CSV or Excel files
48
+ uploaded_file = st.file_uploader("Upload a CSV or Excel file", type=["csv", "xlsx"])
49
+
50
  if st.button("Generate and Download"):
51
+ if app_title:
52
  # Include selected predefined components in the app content
53
  for component in selected_components:
54
  app_content += f"\n{PREDEFINED_COMPONENTS[component]}"
 
56
  # Write generated code to a .py file
57
  file_path = f"{app_title.replace(' ', '_').lower()}_app.py"
58
  with open(file_path, "w") as f:
59
+ f.write(generate_streamlit_app_code(app_title, app_subtitle, side_panel_title, app_content, requirements))
60
 
61
  # Write requirements.txt file
62
  if requirements:
 
71
  with open("requirements.txt", "rb") as req_file:
72
  btn_req = st.download_button(label="Download requirements.txt", data=req_file, file_name="requirements.txt")
73
  else:
74
+ st.warning("Please enter a title for your Streamlit app.")
75
 
76
  if __name__ == "__main__":
77
  main()