Download repochat/utils.py from rcs3/Codebot: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/rcs3/Codebot/resolve/main/repochat/utils.py
- Command line
-
hf download hf://spaces/rcs3/Codebot/repochat/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/rcs3/Codebot/resolve/main/repochat/utils.py
1.03 kB
| import os | |
| import shutil | |
| import subprocess | |
| import streamlit as st | |
| SESSION_DEFAULTS = { | |
| "messages": [], | |
| "chroma_db": None, | |
| "db_loaded": False, | |
| "repo_path": "./cloned_repo", | |
| "git_form": False, | |
| "qa": None, | |
| "db_name": None, | |
| } | |
| def init_session_state(): | |
| for key, default in SESSION_DEFAULTS.items(): | |
| if key not in st.session_state: | |
| st.session_state[key] = default | |
| def clone_repo(git_url: str, repo_path: str): | |
| """Clone a public GitHub repo, stripping the .git metadata afterwards.""" | |
| if os.path.exists(repo_path): | |
| shutil.rmtree(repo_path) | |
| result = subprocess.run( | |
| ["git", "clone", "--depth", "1", git_url, repo_path], | |
| capture_output=True, | |
| text=True, | |
| ) | |
| if result.returncode != 0: | |
| st.error(f"Git clone failed:\n```\n{result.stderr}\n```") | |
| st.stop() | |
| # Remove .git to save disk space | |
| git_dir = os.path.join(repo_path, ".git") | |
| if os.path.exists(git_dir): | |
| shutil.rmtree(git_dir) |