Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,21 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Generate Python code for the Streamlit app
|
| 6 |
code = f"""
|
| 7 |
import streamlit as st
|
| 8 |
|
|
|
|
|
|
|
| 9 |
def main():
|
| 10 |
st.title("{app_title}")
|
| 11 |
{app_content}
|
|
@@ -21,20 +31,37 @@ def main():
|
|
| 21 |
app_title = st.text_input("Enter your Streamlit app title:")
|
| 22 |
app_content = st.text_area("Enter your Streamlit app content (Python code):")
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
if st.button("Generate and Download"):
|
| 25 |
if app_title and app_content:
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Write generated code to a .py file
|
| 29 |
file_path = f"{app_title.replace(' ', '_').lower()}_app.py"
|
| 30 |
with open(file_path, "w") as f:
|
| 31 |
-
f.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
# Download the generated
|
| 34 |
with open(file_path, "rb") as file:
|
| 35 |
btn = st.download_button(label="Download your Streamlit app", data=file, file_name=file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
else:
|
| 37 |
st.warning("Please enter a title and content for your Streamlit app.")
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
| 40 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
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
|
| 16 |
|
| 17 |
+
{requirements}
|
| 18 |
+
|
| 19 |
def main():
|
| 20 |
st.title("{app_title}")
|
| 21 |
{app_content}
|
|
|
|
| 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
|
| 35 |
+
selected_components = st.multiselect("Select predefined components to include:", list(PREDEFINED_COMPONENTS.keys()))
|
| 36 |
+
|
| 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]}"
|
| 45 |
|
| 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:
|
| 53 |
+
with open("requirements.txt", "w") as req_file:
|
| 54 |
+
req_file.write(requirements)
|
| 55 |
|
| 56 |
+
# Download the generated files
|
| 57 |
with open(file_path, "rb") as file:
|
| 58 |
btn = st.download_button(label="Download your Streamlit app", data=file, file_name=file_path)
|
| 59 |
+
|
| 60 |
+
if requirements:
|
| 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()
|