Update app.py
Browse files
app.py
CHANGED
@@ -93,15 +93,54 @@ def workspace_page():
|
|
93 |
# Sidebar with logout button
|
94 |
st.sidebar.title(f"Hello, {st.session_state.username}!")
|
95 |
if st.sidebar.button("Log Out"):
|
96 |
-
# Handle single-click logout
|
97 |
st.session_state.authenticated = False
|
98 |
st.session_state.username = None
|
99 |
st.session_state.page = "login"
|
100 |
|
101 |
# Main content area
|
102 |
st.subheader("Workspace")
|
103 |
-
st.write("This is your personal workspace.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
if __name__ == "__main__":
|
106 |
main()
|
107 |
|
|
|
|
93 |
# Sidebar with logout button
|
94 |
st.sidebar.title(f"Hello, {st.session_state.username}!")
|
95 |
if st.sidebar.button("Log Out"):
|
|
|
96 |
st.session_state.authenticated = False
|
97 |
st.session_state.username = None
|
98 |
st.session_state.page = "login"
|
99 |
|
100 |
# Main content area
|
101 |
st.subheader("Workspace")
|
102 |
+
st.write("This is your personal workspace. You can upload files for a coding project or provide a GitHub repository link.")
|
103 |
+
|
104 |
+
# User action selection
|
105 |
+
action = st.radio("Choose an action", ["Upload Files", "Clone GitHub Repository"], horizontal=True)
|
106 |
+
|
107 |
+
# Handle file uploads
|
108 |
+
if action == "Upload Files":
|
109 |
+
st.subheader("Upload Files")
|
110 |
+
uploaded_files = st.file_uploader("Upload one or more files for your project", accept_multiple_files=True)
|
111 |
+
|
112 |
+
if uploaded_files:
|
113 |
+
user_folder = os.path.join("user_projects", st.session_state.username)
|
114 |
+
os.makedirs(user_folder, exist_ok=True)
|
115 |
+
|
116 |
+
for uploaded_file in uploaded_files:
|
117 |
+
file_path = os.path.join(user_folder, uploaded_file.name)
|
118 |
+
with open(file_path, "wb") as f:
|
119 |
+
f.write(uploaded_file.getbuffer())
|
120 |
+
st.success(f"File {uploaded_file.name} saved successfully!")
|
121 |
+
|
122 |
+
# Handle GitHub repository cloning
|
123 |
+
elif action == "Clone GitHub Repository":
|
124 |
+
st.subheader("Clone GitHub Repository")
|
125 |
+
repo_url = st.text_input("Enter the GitHub repository URL")
|
126 |
+
if st.button("Clone Repository"):
|
127 |
+
if repo_url:
|
128 |
+
user_folder = os.path.join("user_projects", st.session_state.username)
|
129 |
+
os.makedirs(user_folder, exist_ok=True)
|
130 |
+
|
131 |
+
repo_name = repo_url.split("/")[-1].replace(".git", "")
|
132 |
+
repo_path = os.path.join(user_folder, repo_name)
|
133 |
+
|
134 |
+
if not os.path.exists(repo_path):
|
135 |
+
try:
|
136 |
+
Repo.clone_from(repo_url, repo_path)
|
137 |
+
st.success(f"Repository {repo_name} cloned successfully!")
|
138 |
+
except Exception as e:
|
139 |
+
st.error(f"Failed to clone repository: {e}")
|
140 |
+
else:
|
141 |
+
st.warning(f"Repository {repo_name} already exists in your workspace.")
|
142 |
|
143 |
if __name__ == "__main__":
|
144 |
main()
|
145 |
|
146 |
+
|