Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
def generate_streamlit_app_code(app_title, app_content):
|
| 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}
|
| 12 |
+
|
| 13 |
+
if __name__ == "__main__":
|
| 14 |
+
main()
|
| 15 |
+
"""
|
| 16 |
+
return code
|
| 17 |
+
|
| 18 |
+
def main():
|
| 19 |
+
st.title("Streamlit App Generator")
|
| 20 |
+
|
| 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 |
+
app_code = generate_streamlit_app_code(app_title, app_content)
|
| 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(app_code)
|
| 32 |
+
|
| 33 |
+
# Download the generated file
|
| 34 |
+
st.markdown(f"Download your Streamlit app: [**{file_path}**](/{file_path})")
|
| 35 |
+
else:
|
| 36 |
+
st.warning("Please enter a title and content for your Streamlit app.")
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
main()
|