awacke1's picture
Create app.py
3370f55
raw
history blame
824 Bytes
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")