MFF212 commited on
Commit
637fb25
·
1 Parent(s): ee04633

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import subprocess
4
+
5
+ def main():
6
+ st.title("Run Streamlit Apps Within Streamlit")
7
+
8
+ uploaded_file = st.file_uploader("Upload a Streamlit App Python File", type=["py"])
9
+
10
+ if uploaded_file is not None:
11
+ # Save the uploaded file to a temporary location
12
+ with open("temp_app.py", "wb") as f:
13
+ f.write(uploaded_file.getvalue())
14
+
15
+ # Run the uploaded Streamlit app as a subprocess
16
+ cmd = ["streamlit", "run", "temp_app.py"]
17
+
18
+ try:
19
+ st.write("Running the uploaded app...")
20
+ result = subprocess.run(cmd, capture_output=True, text=True, check=True)
21
+ st.write(result.stdout)
22
+ except subprocess.CalledProcessError as e:
23
+ st.error(f"Error running the app:\n{e.stderr}")
24
+
25
+ # Clean up the temporary file
26
+ os.remove("temp_app.py")
27
+
28
+ if __name__ == "__main__":
29
+ main()