Update app.py
Browse files
app.py
CHANGED
@@ -102,16 +102,18 @@ def workspace_page():
|
|
102 |
|
103 |
# Main content area
|
104 |
st.subheader("Workspace")
|
105 |
-
st.write("You can create a new project by uploading files or cloning a GitHub repository.")
|
106 |
|
107 |
# User action selection
|
108 |
-
action = st.radio("Choose an action", ["Upload Files", "Clone GitHub Repository"], horizontal=True)
|
109 |
|
110 |
project_name = st.text_input("Enter a project name")
|
111 |
|
112 |
-
if action == "Upload Files":
|
113 |
-
st.subheader("Upload Files")
|
114 |
-
uploaded_files = st.file_uploader(
|
|
|
|
|
115 |
|
116 |
if uploaded_files and project_name:
|
117 |
if st.button("Upload Project"):
|
@@ -119,10 +121,23 @@ def workspace_page():
|
|
119 |
os.makedirs(user_folder, exist_ok=True)
|
120 |
|
121 |
for uploaded_file in uploaded_files:
|
|
|
122 |
file_path = os.path.join(user_folder, uploaded_file.name)
|
|
|
123 |
with open(file_path, "wb") as f:
|
124 |
f.write(uploaded_file.getbuffer())
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
elif action == "Clone GitHub Repository":
|
128 |
st.subheader("Clone GitHub Repository")
|
|
|
102 |
|
103 |
# Main content area
|
104 |
st.subheader("Workspace")
|
105 |
+
st.write("You can create a new project by uploading files or folders, or by cloning a GitHub repository.")
|
106 |
|
107 |
# User action selection
|
108 |
+
action = st.radio("Choose an action", ["Upload Files or Folders", "Clone GitHub Repository"], horizontal=True)
|
109 |
|
110 |
project_name = st.text_input("Enter a project name")
|
111 |
|
112 |
+
if action == "Upload Files or Folders":
|
113 |
+
st.subheader("Upload Files or Folders")
|
114 |
+
uploaded_files = st.file_uploader(
|
115 |
+
"Upload one or more files or a .zip archive for folders", accept_multiple_files=True
|
116 |
+
)
|
117 |
|
118 |
if uploaded_files and project_name:
|
119 |
if st.button("Upload Project"):
|
|
|
121 |
os.makedirs(user_folder, exist_ok=True)
|
122 |
|
123 |
for uploaded_file in uploaded_files:
|
124 |
+
# Save uploaded .zip files or regular files
|
125 |
file_path = os.path.join(user_folder, uploaded_file.name)
|
126 |
+
|
127 |
with open(file_path, "wb") as f:
|
128 |
f.write(uploaded_file.getbuffer())
|
129 |
+
|
130 |
+
# If a .zip file is uploaded, extract its contents
|
131 |
+
if uploaded_file.name.endswith(".zip"):
|
132 |
+
try:
|
133 |
+
with zipfile.ZipFile(file_path, "r") as zip_ref:
|
134 |
+
zip_ref.extractall(user_folder)
|
135 |
+
os.remove(file_path) # Remove the .zip file after extraction
|
136 |
+
st.success(f"Folder from {uploaded_file.name} extracted successfully!")
|
137 |
+
except zipfile.BadZipFile:
|
138 |
+
st.error(f"File {uploaded_file.name} is not a valid .zip file.")
|
139 |
+
else:
|
140 |
+
st.success(f"File {uploaded_file.name} saved successfully!")
|
141 |
|
142 |
elif action == "Clone GitHub Repository":
|
143 |
st.subheader("Clone GitHub Repository")
|