awacke1 commited on
Commit
a06efbb
ยท
verified ยท
1 Parent(s): 3cf3fce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -6
app.py CHANGED
@@ -166,10 +166,6 @@ def archive_all_data(client):
166
  except Exception as e:
167
  return f"An error occurred while archiving data: {str(e)}"
168
 
169
- # Streamlit app
170
- st.title("๐ŸŒŸ Cosmos DB and GitHub Integration")
171
-
172
-
173
 
174
  # Modify the main app
175
  def main():
@@ -190,7 +186,10 @@ def main():
190
  # Login section
191
  if not st.session_state.logged_in:
192
  st.subheader("๐Ÿ” Login")
193
- input_key = st.text_input("Enter your Cosmos DB key", type="password")
 
 
 
194
  if st.button("๐Ÿš€ Login"):
195
  if input_key:
196
  st.session_state.primary_key = input_key
@@ -247,8 +246,51 @@ def main():
247
  if st.session_state.selected_container:
248
  df = pd.DataFrame(documents)
249
  st.dataframe(df)
 
 
 
 
 
 
250
 
251
- # ... (keep the rest of your existing code for GitHub operations, etc.)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
 
253
  except exceptions.CosmosHttpResponseError as e:
254
  st.error(f"Failed to connect to Cosmos DB. HTTP error: {str(e)}. Status code: {e.status_code}")
 
166
  except Exception as e:
167
  return f"An error occurred while archiving data: {str(e)}"
168
 
 
 
 
 
169
 
170
  # Modify the main app
171
  def main():
 
186
  # Login section
187
  if not st.session_state.logged_in:
188
  st.subheader("๐Ÿ” Login")
189
+ #input_key = st.text_input("Enter your Cosmos DB key", type="password")
190
+ input_key=Key
191
+
192
+ # Cosmos DB configuration
193
  if st.button("๐Ÿš€ Login"):
194
  if input_key:
195
  st.session_state.primary_key = input_key
 
246
  if st.session_state.selected_container:
247
  df = pd.DataFrame(documents)
248
  st.dataframe(df)
249
+
250
+ # GitHub section
251
+ st.subheader("๐Ÿ™ GitHub Operations")
252
+ github_token = os.environ.get("GITHUB") # Read GitHub token from environment variable
253
+ source_repo = st.text_input("Source GitHub Repository URL", value="https://github.com/AaronCWacker/AIExamples-8-24-Streamlit")
254
+ new_repo_name = st.text_input("New Repository Name (for cloning)", value=f"AIExample-Clone-{datetime.now().strftime('%Y%m%d_%H%M%S')}")
255
 
256
+ col1, col2 = st.columns(2)
257
+ with col1:
258
+ if st.button("๐Ÿ“ฅ Clone Repository"):
259
+ if github_token and source_repo:
260
+ try:
261
+ local_path = f"./temp_repo_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
262
+ download_github_repo(source_repo, local_path)
263
+ zip_filename = f"{new_repo_name}.zip"
264
+ create_zip_file(local_path, zip_filename[:-4])
265
+ st.markdown(get_base64_download_link(zip_filename, zip_filename), unsafe_allow_html=True)
266
+ st.success("Repository cloned successfully!")
267
+ except Exception as e:
268
+ st.error(f"An error occurred: {str(e)}")
269
+ finally:
270
+ if os.path.exists(local_path):
271
+ shutil.rmtree(local_path)
272
+ if os.path.exists(zip_filename):
273
+ os.remove(zip_filename)
274
+ else:
275
+ st.error("Please ensure GitHub token is set in environment variables and source repository URL is provided.")
276
+
277
+ with col2:
278
+ if st.button("๐Ÿ“ค Push to New Repository"):
279
+ if github_token and source_repo:
280
+ try:
281
+ g = Github(github_token)
282
+ new_repo = create_repo(g, new_repo_name)
283
+ local_path = f"./temp_repo_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
284
+ download_github_repo(source_repo, local_path)
285
+ push_to_github(local_path, new_repo, github_token)
286
+ st.success(f"Repository pushed successfully to {new_repo.html_url}")
287
+ except Exception as e:
288
+ st.error(f"An error occurred: {str(e)}")
289
+ finally:
290
+ if os.path.exists(local_path):
291
+ shutil.rmtree(local_path)
292
+ else:
293
+ st.error("Please ensure GitHub token is set in environment variables and source repository URL is provided.")
294
 
295
  except exceptions.CosmosHttpResponseError as e:
296
  st.error(f"Failed to connect to Cosmos DB. HTTP error: {str(e)}. Status code: {e.status_code}")