Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import base64
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Read existing app.py
|
6 |
+
with open('app.py', 'r') as f:
|
7 |
+
app_code = f.read()
|
8 |
+
|
9 |
+
# Streamlit UI
|
10 |
+
st.title("Self-Modifying Streamlit App")
|
11 |
+
|
12 |
+
# Textbox for username
|
13 |
+
username = st.text_input("Enter your username:", "anonymous")
|
14 |
+
|
15 |
+
# File Upload
|
16 |
+
uploaded_file = st.file_uploader("Choose a file")
|
17 |
+
if uploaded_file is not None:
|
18 |
+
file_content = uploaded_file.read()
|
19 |
+
|
20 |
+
# Convert file to base64
|
21 |
+
b64 = base64.b64encode(file_content).decode()
|
22 |
+
st.markdown(f"File successfully uploaded. Here is the base64 link:")
|
23 |
+
st.markdown(f"`{b64}`")
|
24 |
+
|
25 |
+
# Modify app.py
|
26 |
+
new_code = f"# Modified by {username}\n"
|
27 |
+
modified_app_code = app_code + "\n" + new_code
|
28 |
+
with open('app.py', 'w') as f:
|
29 |
+
f.write(modified_app_code)
|
30 |
+
|
31 |
+
# Refresh app
|
32 |
+
os.system("streamlit rerun")
|