|
import os
|
|
from github import Github
|
|
import base64
|
|
import shutil
|
|
import zipfile
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
|
|
hf_folder_path = 'api/embeddings'
|
|
zip_name = 'embeddings'
|
|
|
|
|
|
github_token = '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'
|
|
repo_name = 'AdityaMetkar/Patseer-Database'
|
|
folder_path = 'Manual Database/embeddings.zip'
|
|
|
|
|
|
g = Github(github_token)
|
|
repo = g.get_repo(repo_name)
|
|
|
|
|
|
|
|
|
|
def zip_folder():
|
|
shutil.make_archive(zip_name, 'zip', hf_folder_path)
|
|
return zip_name + '.zip'
|
|
|
|
|
|
def update_db():
|
|
|
|
try:
|
|
|
|
existing_file = repo.get_contents(folder_path)
|
|
|
|
compressed_zip = zip_folder()
|
|
with open(compressed_zip, 'rb') as file:
|
|
file_content = file.read()
|
|
|
|
|
|
repo.update_file(existing_file.path, "New DB Update", file_content, existing_file.sha)
|
|
print(f"Updated {folder_path} in GitHub repository.")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
|
|
def download_db():
|
|
if not os.path.exists(hf_folder_path):
|
|
os.makedirs(hf_folder_path)
|
|
|
|
file_content = repo.get_contents(folder_path)
|
|
|
|
try:
|
|
|
|
file_content = repo.get_contents(folder_path)
|
|
zip_data = base64.b64decode(file_content.content)
|
|
|
|
|
|
with zipfile.ZipFile(BytesIO(zip_data)) as zip_ref:
|
|
for file in zip_ref.namelist():
|
|
zip_ref.extract(file, hf_folder_path)
|
|
|
|
print(f"Successfully unzipped files to {hf_folder_path}")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|