Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OS Agnostic Temporary Directory #368

Merged
merged 1 commit into from Jul 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions sweepai/app/ui.py
@@ -1,5 +1,6 @@
import json
import os
import tempfile
from git import Repo
from github import Github
import gradio as gr
Expand Down Expand Up @@ -97,16 +98,17 @@ def get_files(repo_full_name):
repo = github_client.get_repo(repo_full_name)
repo_url = f"https://x-access-token:{config.github_pat}@github.com/{repo_full_name}.git"
try:
if os.path.exists("/tmp/" + repo_full_name):
git_repo = Repo("/tmp/" + repo_full_name)
repo_dir = os.path.join(tempfile.gettempdir(), repo_full_name)
if os.path.exists(repo_dir):
git_repo = Repo(repo_dir)
git_repo.remotes.origin.pull()
else:
Repo.clone_from(repo_url, "/tmp/" + repo_full_name)
Repo.clone_from(repo_url, repo_dir)
except Exception as e:
logger.warning(f"Git pull failed with error {e}, deleting cache and recloning...")
shutil.rmtree("/tmp/" + repo_full_name)
Repo.clone_from(repo_url, "/tmp/" + repo_full_name)
all_files, path_to_contents = get_files_recursively("/tmp/" + repo_full_name)
shutil.rmtree(repo_dir)
Repo.clone_from(repo_url, repo_dir)
all_files, path_to_contents = get_files_recursively(repo_dir)
return all_files

def get_files_update(*args):
Expand All @@ -117,7 +119,6 @@ def get_files_update(*args):
repo = config.repo_full_name
return gr.Dropdown.update(choices=get_files(repo))


with gr.Blocks(theme=gr.themes.Soft(), title="Sweep Chat", css=css) as demo:
print("Launching gradio!")
with gr.Row():
Expand Down