Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ from langchain.docstore.document import Document
|
|
| 17 |
from langchain.schema import Document
|
| 18 |
from chunk_python_code import chunk_python_code_with_metadata
|
| 19 |
from vectorstore import get_chroma_vectorstore
|
|
|
|
| 20 |
|
| 21 |
# Load environment variables from .env file
|
| 22 |
load_dotenv()
|
|
@@ -53,55 +54,6 @@ def load_project_id(json_file):
|
|
| 53 |
return data['project_id']
|
| 54 |
|
| 55 |
|
| 56 |
-
def download_gitlab_project_by_version():
|
| 57 |
-
try:
|
| 58 |
-
# Load the configuration from config.json
|
| 59 |
-
|
| 60 |
-
# Extract GitLab project information from the config
|
| 61 |
-
api_url = config2['gitlab']['api_url']
|
| 62 |
-
project_id = urllib.parse.quote(config2['gitlab']['project']['id'], safe="")
|
| 63 |
-
version = config2['gitlab']['project']['version']
|
| 64 |
-
|
| 65 |
-
# Construct the URL for the release's zip file
|
| 66 |
-
url = f"{api_url}/projects/{project_id}/repository/archive.zip?sha={version}"
|
| 67 |
-
|
| 68 |
-
# Send GET request to download the zip file
|
| 69 |
-
response = requests.get(url, stream=True)
|
| 70 |
-
archive_bytes = io.BytesIO(response.content)
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
if response.status_code == 200:
|
| 74 |
-
# Extract filename from content-disposition header
|
| 75 |
-
content_disposition = response.headers.get("content-disposition")
|
| 76 |
-
if content_disposition and "filename=" in content_disposition:
|
| 77 |
-
filename = content_disposition.split("filename=")[-1].strip('"')
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
# test
|
| 81 |
-
# target_path = f"{DATA_DIR}/{filename}"
|
| 82 |
-
|
| 83 |
-
# Check if the request was successful
|
| 84 |
-
if response.status_code == 200:
|
| 85 |
-
api.upload_file(
|
| 86 |
-
path_or_fileobj= archive_bytes,
|
| 87 |
-
path_in_repo= f"{DATA_DIR}/{filename}",
|
| 88 |
-
repo_id=HF_SPACE_NAME,
|
| 89 |
-
repo_type='space'
|
| 90 |
-
)
|
| 91 |
-
print(f"Release {version} downloaded successfully as {file_path}.")
|
| 92 |
-
else:
|
| 93 |
-
print(f"Failed to download the release: {response.status_code} - {response.reason}")
|
| 94 |
-
print(response.text)
|
| 95 |
-
|
| 96 |
-
except FileNotFoundError:
|
| 97 |
-
print("The config.json file was not found. Please ensure it exists in the project directory.")
|
| 98 |
-
except json.JSONDecodeError:
|
| 99 |
-
print("Failed to parse the config.json file. Please ensure it contains valid JSON.")
|
| 100 |
-
except Exception as e:
|
| 101 |
-
print(f"An error occurred: {e}")
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
def download_gitlab_repo():
|
| 106 |
print("Start the upload_gitRepository function")
|
| 107 |
project_id = load_project_id('repository_ids.json')
|
|
@@ -329,16 +281,14 @@ def get_chroma_vectorstore2(embedding_model):
|
|
| 329 |
def initialize():
|
| 330 |
global vector_store, chunks, llm
|
| 331 |
|
| 332 |
-
|
| 333 |
|
| 334 |
code_folder_paths = ['kadi_apy']
|
| 335 |
doc_folder_paths = ['docs/source/']
|
| 336 |
-
|
| 337 |
-
|
| 338 |
code_texts, code_references = process_directory(DATA_DIR, code_folder_paths, [])
|
| 339 |
print("LEEEEEEEEEEEENGTH of code_texts: ", len(code_texts))
|
| 340 |
-
|
| 341 |
-
|
| 342 |
doc_texts, kadiAPY_doc_references = process_directory(DATA_DIR, doc_folder_paths, [])
|
| 343 |
print("LEEEEEEEEEEEENGTH of doc_files: ", len(doc_texts))
|
| 344 |
|
|
|
|
| 17 |
from langchain.schema import Document
|
| 18 |
from chunk_python_code import chunk_python_code_with_metadata
|
| 19 |
from vectorstore import get_chroma_vectorstore
|
| 20 |
+
from download_gitlab_repo import download_and_upload_kadiAPY_repo_to_huggingfacespace
|
| 21 |
|
| 22 |
# Load environment variables from .env file
|
| 23 |
load_dotenv()
|
|
|
|
| 54 |
return data['project_id']
|
| 55 |
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
def download_gitlab_repo():
|
| 58 |
print("Start the upload_gitRepository function")
|
| 59 |
project_id = load_project_id('repository_ids.json')
|
|
|
|
| 281 |
def initialize():
|
| 282 |
global vector_store, chunks, llm
|
| 283 |
|
| 284 |
+
download_and_upload_kadiAPY_repo_to_huggingfacespace()
|
| 285 |
|
| 286 |
code_folder_paths = ['kadi_apy']
|
| 287 |
doc_folder_paths = ['docs/source/']
|
| 288 |
+
|
|
|
|
| 289 |
code_texts, code_references = process_directory(DATA_DIR, code_folder_paths, [])
|
| 290 |
print("LEEEEEEEEEEEENGTH of code_texts: ", len(code_texts))
|
| 291 |
+
|
|
|
|
| 292 |
doc_texts, kadiAPY_doc_references = process_directory(DATA_DIR, doc_folder_paths, [])
|
| 293 |
print("LEEEEEEEEEEEENGTH of doc_files: ", len(doc_texts))
|
| 294 |
|