-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f44e452
commit 054abec
Showing
14 changed files
with
512 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Module for handling user configuration and updating the models.""" | ||
|
||
import json | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
|
||
from models.conversation import Conversation | ||
from models.conversation_list import ConversationList | ||
from models.message import Message | ||
from models.node import Node | ||
from views.prompt_user import prompt_user | ||
|
||
CONFIG_PATH = Path("config.json") | ||
|
||
HOME: Path = Path.home() | ||
DOWNLOADS: Path = HOME / "Downloads" | ||
|
||
# most recent zip file in downloads folder | ||
DEFAULT_ZIP_FILE: Path = max(DOWNLOADS.glob("*.zip"), key=lambda x: x.stat().st_ctime) | ||
|
||
DEFAULT_OUTPUT_FOLDER: Path = HOME / "Documents" / "ChatGPT Data" | ||
|
||
|
||
def get_user_configs() -> Dict[str, Any]: | ||
"""Prompt the user for configuration options, with defaults from the config file. | ||
Returns the user configuration as a dictionary.""" | ||
|
||
with open(CONFIG_PATH, "r", encoding="utf-8") as file: | ||
default_configs = json.load(file) | ||
|
||
if not default_configs["zip_file"]: | ||
default_configs["zip_file"] = str(DEFAULT_ZIP_FILE) | ||
|
||
if not default_configs["output_folder"]: | ||
default_configs["output_folder"] = str(DEFAULT_OUTPUT_FOLDER) | ||
|
||
# DEBUG | ||
print("DEBUG: loaded default configs") | ||
|
||
return prompt_user(default_configs) | ||
|
||
|
||
def update_config_file(user_configs: Dict[str, Any]) -> None: | ||
"""Update the config file with the user's configuration options.""" | ||
with open(CONFIG_PATH, "w", encoding="utf-8") as file: | ||
json.dump(user_configs, file, indent=2) | ||
|
||
|
||
def set_model_configs(configs: Dict[str, Any]) -> None: | ||
"""Set the configuration for all models.""" | ||
Conversation.configuration = configs.get("conversation", {}) | ||
ConversationList.configuration = configs.get("conversation_list", {}) | ||
Message.configuration = configs.get("message", {}) | ||
Node.configuration = configs.get("node", {}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
"""Module for various processes that are used in the controllers.""" | ||
|
||
|
||
import json | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
from zipfile import ZipFile | ||
|
||
from tqdm import tqdm | ||
|
||
from models.conversation_list import ConversationList | ||
|
||
from .data_visualizations import create_save_wordcloud | ||
|
||
|
||
def load_conversations_from_zip(zip_filepath: Path) -> ConversationList: | ||
"""Load the conversations from the zip file.""" | ||
|
||
with ZipFile(zip_filepath, "r") as file: | ||
file.extractall(zip_filepath.with_suffix("")) | ||
|
||
conversations_path = zip_filepath.with_suffix("") / "conversations.json" | ||
|
||
with open(conversations_path, "r", encoding="utf-8") as file: | ||
conversations = json.load(file) | ||
|
||
return ConversationList(conversations) | ||
|
||
|
||
def write_markdown_files( | ||
conversation_list: ConversationList, markdown_folder: Path | ||
) -> None: | ||
"""Write the markdown files for the conversations in the conversation list.""" | ||
|
||
for conversation in tqdm( | ||
conversation_list.conversations, desc="Writing Markdown 📄 files" | ||
): | ||
file_path = markdown_folder / f"{conversation.sanitized_title()}.md" | ||
conversation.save_to_file(file_path) | ||
|
||
|
||
def create_wordclouds( | ||
conversation_list: ConversationList, wordcloud_folder: Path, configs: Dict[str, Any] | ||
) -> None: | ||
"""Create the wordclouds for the conversations in the conversation list.""" | ||
|
||
weeks_dict = conversation_list.grouped_by_week() | ||
months_dict = conversation_list.grouped_by_month() | ||
years_dict = conversation_list.grouped_by_year() | ||
|
||
font_path = Path("assets/fonts") / f"{configs['wordcloud']['font']}.ttf" | ||
|
||
colormap = configs["wordcloud"]["colormap"] | ||
|
||
for week in tqdm(weeks_dict.keys(), desc="Creating weekly wordclouds 🔡☁️ "): | ||
entire_week_text = ( | ||
weeks_dict[week].all_user_text() | ||
+ "\n" | ||
+ weeks_dict[week].all_assistant_text() | ||
) | ||
|
||
create_save_wordcloud( | ||
entire_week_text, | ||
wordcloud_folder / f"{week.strftime('%Y week %W')}.png", | ||
font_path=str(font_path), | ||
colormap=colormap, | ||
) | ||
|
||
for month in tqdm(months_dict.keys(), desc="Creating monthly wordclouds 🔡☁️ "): | ||
entire_month_text = ( | ||
months_dict[month].all_user_text() | ||
+ "\n" | ||
+ months_dict[month].all_assistant_text() | ||
) | ||
|
||
create_save_wordcloud( | ||
entire_month_text, | ||
wordcloud_folder / f"{month.strftime('%B %Y')}.png", | ||
font_path=str(font_path), | ||
colormap=colormap, | ||
) | ||
|
||
for year in tqdm(years_dict.keys(), desc="Creating yearly wordclouds 🔡☁️ "): | ||
entire_year_text = ( | ||
years_dict[year].all_user_text() | ||
+ "\n" | ||
+ years_dict[year].all_assistant_text() | ||
) | ||
|
||
create_save_wordcloud( | ||
entire_year_text, | ||
wordcloud_folder / f"{year.strftime('%Y')}.png", | ||
font_path=str(font_path), | ||
colormap=colormap, | ||
) | ||
|
||
|
||
def write_custom_instructions( | ||
conversation_list: ConversationList, file_path: Path | ||
) -> None: | ||
"""Create JSON file for custom instructions in the conversation list.""" | ||
|
||
with open(file_path, "w", encoding="utf-8") as file: | ||
json.dump(conversation_list.all_custom_instructions(), file, indent=2) |
Oops, something went wrong.