Spaces:
Sleeping
Sleeping
import streamlit as st | |
import base64 | |
import os | |
# Read existing app.py | |
with open('app.py', 'r') as f: | |
app_code = f.read() | |
# Streamlit UI | |
st.title("Self-Modifying Streamlit App") | |
# Textbox for username | |
username = st.text_input("Enter your username:", "anonymous") | |
# File Upload | |
uploaded_file = st.file_uploader("Choose a file") | |
if uploaded_file is not None: | |
file_content = uploaded_file.read() | |
# Convert file to base64 | |
b64 = base64.b64encode(file_content).decode() | |
st.markdown(f"File successfully uploaded. Here is the download link:") | |
# Create a download link | |
href = f'<a href="data:file/txt;base64,{b64}" download="your_file.txt">Download File</a>' | |
st.markdown(href, unsafe_allow_html=True) | |
# Modify app.py | |
new_code = f"# Modified by {username}\n" | |
modified_app_code = app_code + "\n" + new_code | |
with open('app.py', 'w') as f: | |
f.write(modified_app_code) | |
# Refresh app | |
os.system("streamlit rerun") | |