Update app.py
Browse files
app.py
CHANGED
@@ -105,22 +105,36 @@ def workspace_page():
|
|
105 |
st.write("This is your personal workspace. You can upload files for a coding project or provide a GitHub repository link.")
|
106 |
|
107 |
# User action selection
|
108 |
-
action = st.radio("Choose an action", ["Upload Files", "Clone GitHub Repository"], horizontal=True)
|
109 |
|
110 |
-
# Handle file uploads
|
111 |
-
if action == "Upload Files":
|
112 |
-
st.subheader("Upload Files")
|
113 |
-
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
|
125 |
# Handle GitHub repository cloning
|
126 |
elif action == "Clone GitHub Repository":
|
@@ -137,11 +151,11 @@ def workspace_page():
|
|
137 |
if not os.path.exists(repo_path):
|
138 |
try:
|
139 |
Repo.clone_from(repo_url, repo_path)
|
140 |
-
st.success(f"Repository {repo_name} cloned successfully!")
|
141 |
except Exception as e:
|
142 |
st.error(f"Failed to clone repository: {e}")
|
143 |
else:
|
144 |
-
st.warning(f"Repository {repo_name} already exists in your workspace.")
|
145 |
|
146 |
if __name__ == "__main__":
|
147 |
main()
|
|
|
105 |
st.write("This is your personal workspace. You can upload files for a coding project or provide a GitHub repository link.")
|
106 |
|
107 |
# User action selection
|
108 |
+
action = st.radio("Choose an action", ["Upload Project Files", "Clone GitHub Repository"], horizontal=True)
|
109 |
|
110 |
+
# Handle file uploads as a project
|
111 |
+
if action == "Upload Project Files":
|
112 |
+
st.subheader("Upload Project Files")
|
113 |
+
project_name = st.text_input("Enter a name for your project")
|
114 |
|
115 |
+
uploaded_files = st.file_uploader(
|
116 |
+
"Upload one or more files for your project",
|
117 |
+
accept_multiple_files=True
|
118 |
+
)
|
119 |
+
|
120 |
+
if project_name and uploaded_files:
|
121 |
+
if st.button("Upload Project"):
|
122 |
+
user_folder = os.path.join("user_projects", st.session_state.username)
|
123 |
+
project_folder = os.path.join(user_folder, project_name)
|
124 |
+
|
125 |
+
if not os.path.exists(project_folder):
|
126 |
+
os.makedirs(project_folder)
|
127 |
+
|
128 |
+
for uploaded_file in uploaded_files:
|
129 |
+
file_path = os.path.join(project_folder, uploaded_file.name)
|
130 |
+
with open(file_path, "wb") as f:
|
131 |
+
f.write(uploaded_file.getbuffer())
|
132 |
|
133 |
+
st.success(f"Project '{project_name}' uploaded successfully with {len(uploaded_files)} file(s)!")
|
134 |
+
elif not project_name:
|
135 |
+
st.warning("Please enter a project name.")
|
136 |
+
elif not uploaded_files:
|
137 |
+
st.warning("Please upload at least one file.")
|
138 |
|
139 |
# Handle GitHub repository cloning
|
140 |
elif action == "Clone GitHub Repository":
|
|
|
151 |
if not os.path.exists(repo_path):
|
152 |
try:
|
153 |
Repo.clone_from(repo_url, repo_path)
|
154 |
+
st.success(f"Repository '{repo_name}' cloned successfully!")
|
155 |
except Exception as e:
|
156 |
st.error(f"Failed to clone repository: {e}")
|
157 |
else:
|
158 |
+
st.warning(f"Repository '{repo_name}' already exists in your workspace.")
|
159 |
|
160 |
if __name__ == "__main__":
|
161 |
main()
|