Update app.py
Browse files
app.py
CHANGED
@@ -102,60 +102,42 @@ def workspace_page():
|
|
102 |
|
103 |
# Main content area
|
104 |
st.subheader("Workspace")
|
105 |
-
st.write("
|
106 |
|
107 |
# User action selection
|
108 |
-
action = st.radio("Choose an action", ["Upload
|
109 |
|
110 |
-
|
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 |
-
|
116 |
-
|
117 |
-
|
118 |
-
)
|
119 |
|
120 |
-
if
|
121 |
if st.button("Upload Project"):
|
122 |
-
user_folder = os.path.join("user_projects", st.session_state.username)
|
123 |
-
|
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(
|
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":
|
141 |
st.subheader("Clone GitHub Repository")
|
142 |
repo_url = st.text_input("Enter the GitHub repository URL")
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
146 |
os.makedirs(user_folder, exist_ok=True)
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
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()
|
|
|
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("Upload one or more files for your project", accept_multiple_files=True)
|
|
|
115 |
|
116 |
+
if uploaded_files and project_name:
|
117 |
if st.button("Upload Project"):
|
118 |
+
user_folder = os.path.join("user_projects", st.session_state.username, project_name)
|
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 |
+
st.success(f"Project '{project_name}' uploaded successfully!")
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
elif action == "Clone GitHub Repository":
|
128 |
st.subheader("Clone GitHub Repository")
|
129 |
repo_url = st.text_input("Enter the GitHub repository URL")
|
130 |
+
|
131 |
+
if repo_url and project_name:
|
132 |
+
if st.button("Upload Project"):
|
133 |
+
user_folder = os.path.join("user_projects", st.session_state.username, project_name)
|
134 |
os.makedirs(user_folder, exist_ok=True)
|
135 |
|
136 |
+
try:
|
137 |
+
Repo.clone_from(repo_url, user_folder)
|
138 |
+
st.success(f"Project '{project_name}' cloned successfully!")
|
139 |
+
except Exception as e:
|
140 |
+
st.error(f"Failed to clone repository: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
if __name__ == "__main__":
|
143 |
main()
|