Spaces:
Running
Running

Remove Hugging Face token from database download in manage.py and streamline Dockerfile login command
0a9c507
#!/usr/bin/env python | |
"""Django's command-line utility for administrative tasks.""" | |
import os | |
import sys | |
import time | |
import shutil | |
if os.environ.get('INSIDEDOCKER'): | |
db_file = os.path.join(os.getcwd(), "db.sqlite3") | |
if os.path.exists(db_file) and (time.time() - os.path.getmtime(db_file) < 300): | |
print("db.sqlite3 exists and is recent. Skipping download.") | |
else: | |
from huggingface_hub import hf_hub_download | |
custom_cache_dir = os.path.expanduser("/app/.cache/huggingface") | |
file_path = hf_hub_download( | |
repo_id="SushantGautam/BridgeMentor", | |
filename="db.sqlite3", | |
repo_type="dataset", | |
cache_dir=custom_cache_dir | |
) | |
print(f"Downloaded to: {file_path}") | |
destination_path = os.path.join(os.getcwd(), "db.sqlite3") | |
shutil.copy(file_path, destination_path) | |
print(f"db.sqlite3 Copied to current directory: {destination_path}") | |
def main(): | |
"""Run administrative tasks.""" | |
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BridgeMentor.settings') | |
try: | |
from django.core.management import execute_from_command_line | |
except ImportError as exc: | |
raise ImportError( | |
"Couldn't import Django. Are you sure it's installed and " | |
"available on your PYTHONPATH environment variable? Did you " | |
"forget to activate a virtual environment?" | |
) from exc | |
execute_from_command_line(sys.argv) | |
if __name__ == '__main__': | |
main() | |