Spaces:
Sleeping
Sleeping
File size: 824 Bytes
3370f55 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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 base64 link:")
st.markdown(f"`{b64}`")
# 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")
|