Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,14 +69,12 @@ def download_gitlab_project_by_version():
|
|
| 69 |
response = requests.get(url, stream=True)
|
| 70 |
archive_bytes = io.BytesIO(response.content)
|
| 71 |
|
| 72 |
-
print(archive_bytes)
|
| 73 |
|
| 74 |
if response.status_code == 200:
|
| 75 |
# Extract filename from content-disposition header
|
| 76 |
content_disposition = response.headers.get("content-disposition")
|
| 77 |
if content_disposition and "filename=" in content_disposition:
|
| 78 |
filename = content_disposition.split("filename=")[-1].strip('"')
|
| 79 |
-
print(filename)
|
| 80 |
|
| 81 |
|
| 82 |
# test
|
|
@@ -150,9 +148,7 @@ def download_gitlab_repo():
|
|
| 150 |
def get_all_files_in_folder(temp_dir, folder_path):
|
| 151 |
|
| 152 |
all_files = []
|
| 153 |
-
print("inner method of get all files in folder")
|
| 154 |
target_dir = os.path.join(temp_dir, folder_path)
|
| 155 |
-
print(target_dir)
|
| 156 |
|
| 157 |
for root, dirs, files in os.walk(target_dir):
|
| 158 |
print(f"Files in current directory ({root}): {files}")
|
|
@@ -171,11 +167,8 @@ def process_directory(directory, folder_paths, file_paths):
|
|
| 171 |
all_texts = []
|
| 172 |
file_references = []
|
| 173 |
|
| 174 |
-
zip_filename = next((file for file in os.listdir(directory) if file.endswith('.zip')), None)
|
| 175 |
-
|
| 176 |
-
zip_file_path = os.path.join(directory, zip_filename) # zip_file_path: data/kadi-apy-master-2a244f1af1483b48f8f9c0d99ce2744a0950c834.zip
|
| 177 |
-
print("zip_file_path:", zip_file_path)
|
| 178 |
-
# zip_file_path = os.listdir(directory) if file.endswith('.zip')
|
| 179 |
|
| 180 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 181 |
# Unzip the file into the temporary directory
|
|
@@ -183,11 +176,11 @@ def process_directory(directory, folder_paths, file_paths):
|
|
| 183 |
zip_ref.extractall(tmpdirname)
|
| 184 |
|
| 185 |
files = []
|
| 186 |
-
print("tmpdirname: " , tmpdirname)
|
| 187 |
unzipped_root = os.listdir(tmpdirname)
|
| 188 |
-
print("unzipped_root ", unzipped_root)
|
| 189 |
|
| 190 |
-
tmpsubdirpath= os.path.join(tmpdirname, unzipped_root[0])
|
| 191 |
print("tempsubdirpath: ", tmpsubdirpath)
|
| 192 |
|
| 193 |
if folder_paths:
|
|
@@ -216,7 +209,6 @@ def process_directory(directory, folder_paths, file_paths):
|
|
| 216 |
relative_path = os.path.relpath(file_path, tmpsubdirpath)
|
| 217 |
print("Relative Filepaths brother:", relative_path)
|
| 218 |
file_references.append(relative_path)
|
| 219 |
-
print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA: ", relative_path)
|
| 220 |
|
| 221 |
return all_texts, file_references
|
| 222 |
|
|
@@ -312,6 +304,7 @@ def format_kadi_apy_library_context(docs):
|
|
| 312 |
type_info = doc.metadata.get("type", "Unknown Type")
|
| 313 |
source_info = doc.metadata.get("source", "Unknown Type")
|
| 314 |
# Format metadata and document content
|
|
|
|
| 315 |
formatted_doc = f"# source: {source_info}\n# class: {class_info}\n# type: {type_info}\n{doc.page_content}\n\n\n"
|
| 316 |
doc_context.append(formatted_doc)
|
| 317 |
|
|
@@ -342,9 +335,9 @@ def rag_workflow(query):
|
|
| 342 |
kadi_apy_library_docs = retrieve_within_kadiApy_library (vector_store, query, k = 10)
|
| 343 |
|
| 344 |
doc_context = format_kadi_api_doc_context(kadi_apy_docs)
|
| 345 |
-
print(doc_context)
|
| 346 |
code_context = format_kadi_apy_library_context(kadi_apy_library_docs)
|
| 347 |
-
print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:",code_context)
|
| 348 |
|
| 349 |
|
| 350 |
|
|
|
|
| 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
|
|
|
|
| 148 |
def get_all_files_in_folder(temp_dir, folder_path):
|
| 149 |
|
| 150 |
all_files = []
|
|
|
|
| 151 |
target_dir = os.path.join(temp_dir, folder_path)
|
|
|
|
| 152 |
|
| 153 |
for root, dirs, files in os.walk(target_dir):
|
| 154 |
print(f"Files in current directory ({root}): {files}")
|
|
|
|
| 167 |
all_texts = []
|
| 168 |
file_references = []
|
| 169 |
|
| 170 |
+
zip_filename = next((file for file in os.listdir(directory) if file.endswith('.zip')), None)
|
| 171 |
+
zip_file_path = os.path.join(directory, zip_filename)
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
with tempfile.TemporaryDirectory() as tmpdirname:
|
| 174 |
# Unzip the file into the temporary directory
|
|
|
|
| 176 |
zip_ref.extractall(tmpdirname)
|
| 177 |
|
| 178 |
files = []
|
| 179 |
+
print("tmpdirname: " , tmpdirname)
|
| 180 |
unzipped_root = os.listdir(tmpdirname)
|
| 181 |
+
print("unzipped_root ", unzipped_root)
|
| 182 |
|
| 183 |
+
tmpsubdirpath= os.path.join(tmpdirname, unzipped_root[0])
|
| 184 |
print("tempsubdirpath: ", tmpsubdirpath)
|
| 185 |
|
| 186 |
if folder_paths:
|
|
|
|
| 209 |
relative_path = os.path.relpath(file_path, tmpsubdirpath)
|
| 210 |
print("Relative Filepaths brother:", relative_path)
|
| 211 |
file_references.append(relative_path)
|
|
|
|
| 212 |
|
| 213 |
return all_texts, file_references
|
| 214 |
|
|
|
|
| 304 |
type_info = doc.metadata.get("type", "Unknown Type")
|
| 305 |
source_info = doc.metadata.get("source", "Unknown Type")
|
| 306 |
# Format metadata and document content
|
| 307 |
+
print("YYYYYYYEEEEEEEEEEEEEEE222222222222222222222222222222:}\n\n", doc.page_content)
|
| 308 |
formatted_doc = f"# source: {source_info}\n# class: {class_info}\n# type: {type_info}\n{doc.page_content}\n\n\n"
|
| 309 |
doc_context.append(formatted_doc)
|
| 310 |
|
|
|
|
| 335 |
kadi_apy_library_docs = retrieve_within_kadiApy_library (vector_store, query, k = 10)
|
| 336 |
|
| 337 |
doc_context = format_kadi_api_doc_context(kadi_apy_docs)
|
| 338 |
+
#print(doc_context)
|
| 339 |
code_context = format_kadi_apy_library_context(kadi_apy_library_docs)
|
| 340 |
+
#print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:",code_context)
|
| 341 |
|
| 342 |
|
| 343 |
|