Spaces:
Sleeping
Sleeping
| import json | |
| import os | |
| from typing import Any | |
| def get_session_dir() -> str: | |
| sessions_dir = os.path.join( | |
| os.path.dirname(__file__), | |
| '..', '..', 'sessions' | |
| ) | |
| if not os.path.exists(sessions_dir): | |
| os.mkdir(sessions_dir) | |
| return sessions_dir | |
| def save_information( | |
| information: Any, | |
| filepath: str | |
| ) -> None: | |
| with open(filepath, 'w', encoding='utf-8') as f: | |
| json.dump(information, f, ensure_ascii=False, indent=4) | |
| def load_information(filepath: str) -> Any: | |
| with open(filepath, 'r', encoding='utf-8') as f: | |
| content = json.load(f) | |
| return content | |
| def transform_story_name( | |
| story_name: str, | |
| is_inverse: bool = False | |
| ) -> str: | |
| if is_inverse: | |
| return ' '.join([word.capitalize() for word in story_name.split(' ')]) | |
| else: | |
| return story_name.lower().replace(' ', '_') | |