Spaces:
Runtime error
Runtime error
Update describepdf/config.py
Browse files- describepdf/config.py +33 -1
describepdf/config.py
CHANGED
|
@@ -14,9 +14,41 @@ import pathlib
|
|
| 14 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - [%(module)s] - %(message)s')
|
| 15 |
logger = logging.getLogger('describepdf')
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Directory containing prompt templates (making path absolute by using current file location)
|
| 18 |
SCRIPT_DIR = pathlib.Path(__file__).parent.parent.absolute()
|
| 19 |
-
PROMPTS_DIR =
|
| 20 |
|
| 21 |
# Default configuration values
|
| 22 |
DEFAULT_CONFIG: Dict[str, Any] = {
|
|
|
|
| 14 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - [%(module)s] - %(message)s')
|
| 15 |
logger = logging.getLogger('describepdf')
|
| 16 |
|
| 17 |
+
def _resolve_prompts_directory() -> pathlib.Path:
|
| 18 |
+
"""
|
| 19 |
+
Resolve the path to the prompts directory with multiple fallback strategies.
|
| 20 |
+
Returns:
|
| 21 |
+
pathlib.Path: Path to the prompts directory
|
| 22 |
+
"""
|
| 23 |
+
# List of potential paths to check
|
| 24 |
+
potential_paths = [
|
| 25 |
+
# Current file's parent directory
|
| 26 |
+
pathlib.Path(__file__).parent.parent / "prompts",
|
| 27 |
+
|
| 28 |
+
# Relative to the current working directory
|
| 29 |
+
pathlib.Path.cwd() / "prompts",
|
| 30 |
+
|
| 31 |
+
# Absolute path fallback (useful in deployment)
|
| 32 |
+
pathlib.Path("/app/prompts"),
|
| 33 |
+
pathlib.Path("/workspace/prompts"),
|
| 34 |
+
|
| 35 |
+
# Hugging Face Spaces specific path
|
| 36 |
+
pathlib.Path("/home/user/app/prompts")
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
# Try each path
|
| 40 |
+
for path in potential_paths:
|
| 41 |
+
if path.is_dir():
|
| 42 |
+
logger.info(f"Prompts directory found at: {path}")
|
| 43 |
+
return path
|
| 44 |
+
|
| 45 |
+
# If no path is found
|
| 46 |
+
logger.error("Could not locate prompts directory. Using a temporary fallback.")
|
| 47 |
+
return pathlib.Path(__file__).parent / "prompts"
|
| 48 |
+
|
| 49 |
# Directory containing prompt templates (making path absolute by using current file location)
|
| 50 |
SCRIPT_DIR = pathlib.Path(__file__).parent.parent.absolute()
|
| 51 |
+
PROMPTS_DIR = _resolve_prompts_directory()
|
| 52 |
|
| 53 |
# Default configuration values
|
| 54 |
DEFAULT_CONFIG: Dict[str, Any] = {
|