Spaces:
Sleeping
Sleeping
Download src/controllers/BaseController.py from mustaphaelkady/mini-rag: direct link, hf CLI and curl.
- Browser
- Download file 849 Bytes
-
https://huggingface.co/spaces/mustaphaelkady/mini-rag/resolve/main/src/controllers/BaseController.py
- Command line
-
hf download hf://spaces/mustaphaelkady/mini-rag/src/controllers/BaseController.py
-
curl -L -o BaseController.py https://huggingface.co/spaces/mustaphaelkady/mini-rag/resolve/main/src/controllers/BaseController.py
849 Bytes
| from helpers.config import get_settings, Settings | |
| import os | |
| import random | |
| import string | |
| class BaseController: | |
| def __init__(self): | |
| self.app_settings = get_settings() | |
| self.base_dir = os.path.dirname(os.path.dirname(__file__)) | |
| self.files_dir = os.path.join( | |
| self.base_dir, | |
| "assets/files" ) | |
| self.databases_dir = os.path.join( | |
| self.base_dir, | |
| "assets/databases" | |
| ) | |
| # gemerate random string with size 12 | |
| def generate_random_string(self, length: int=12): | |
| return ''.join(random.choices(string.ascii_lowercase + string.digits, k=length)) | |
| def get_database_path(self, db_name: str): | |
| if not os.path.exists(self.databases_dir): | |
| os.makedirs(self.databases_dir) | |
| return os.path.join(self.databases_dir, db_name) | |