Spaces:
Build error
Build error
Download guide_manager.py from sp103107/growing-guide: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/sp103107/growing-guide/resolve/main/guide_manager.py
- Command line
-
hf download hf://spaces/sp103107/growing-guide/guide_manager.py
-
curl -L -o guide_manager.py https://huggingface.co/spaces/sp103107/growing-guide/resolve/main/guide_manager.py
1.5 kB
| from typing import Dict, List | |
| import logging | |
| import json | |
| from pathlib import Path | |
| logger = logging.getLogger(__name__) | |
| class GrowingGuideManager: | |
| def __init__(self): | |
| self.guides = [] | |
| def load_guides(self, guides_path: Path) -> List[Dict]: | |
| """Load guides from the data directory""" | |
| guides = [] | |
| if guides_path.exists(): | |
| logger.info(f"Loading guides from {guides_path}") | |
| for guide_file in guides_path.glob("*.json"): | |
| try: | |
| logger.info(f"Processing guide file: {guide_file}") | |
| with open(guide_file, 'r', encoding='utf-8') as f: | |
| guide_data = json.load(f) | |
| guides.append(guide_data) | |
| logger.info(f"Successfully loaded guide for: {guide_data.get('strain_name')}") | |
| except Exception as e: | |
| logger.error(f"Error loading guide {guide_file}: {str(e)}") | |
| else: | |
| logger.warning(f"Guides path does not exist: {guides_path}") | |
| self.guides = guides | |
| return guides | |
| def get_guide_by_strain(self, strain_name: str) -> Dict: | |
| """Get a specific guide by strain name""" | |
| for guide in self.guides: | |
| if guide.get('strain_name', '').lower() == strain_name.lower(): | |
| return guide | |
| return None | |
| def get_all_guides(self) -> List[Dict]: | |
| """Get all loaded guides""" | |
| return self.guides |