-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (30 loc) · 950 Bytes
/
main.py
File metadata and controls
37 lines (30 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import shutil # copy files
import stat # to
from dotenv import load_dotenv
from app.embeddings.embedder import CodeEmbedder
# Load environment variables
load_dotenv()
REPO_DIR = "data/repos"
FAISS_DIR = "data/faiss_index"
def remove_readonly(func, path, _):
"""Handler for readonly files on Windows."""
os.chmod(path, stat.S_IWRITE)
func(path)
# Clean old repos and FAISS indexes safely
for path in [REPO_DIR, FAISS_DIR]:
if os.path.exists(path):
shutil.rmtree(path, onerror=remove_readonly)
os.makedirs(path, exist_ok=True)
print("Cleaned old repos and FAISS indexes safely.")
# Preload CodeBERT model once
print("Loading SentenceTransformer model...")
try:
embedder = CodeEmbedder()
except Exception as e:
print(f"Error loading SentenceTransformer: {e}")
else:
print("SentenceTransformer model loaded successfully.")
# Launch Gradio app
from app.ui.gradio_app import launch_ui
launch_ui()