Skip to content

Commit

Permalink
Reformatting project
Browse files Browse the repository at this point in the history
  • Loading branch information
thtroyer committed Mar 9, 2022
1 parent e476ac4 commit c8ea568
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 39 deletions.
4 changes: 2 additions & 2 deletions run_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import os
import pathlib
import shutil
import tensorflow
import sys

import tensorflow

from simpletextgenerator import training, jobs_util
from simpletextgenerator.jobs_util import resource_path
from simpletextgenerator.logging_setup import setup_logging
Expand All @@ -19,7 +20,6 @@
except IndexError as ignored:
pass


project_dir = "./projects"
to_run_dir = "to_run"
output_dir = "output"
Expand Down
2 changes: 1 addition & 1 deletion simple-text-generator-ui.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import hashlib
import logging
import os
import pathlib
import subprocess
import sys
import os

from simpletextgenerator.logging_setup import setup_logging
from simpletextgenerator.ui.menu import draw_main_menu
Expand Down
3 changes: 2 additions & 1 deletion simpletextgenerator/jobs_util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import os
import sys

import yaml
import logging

from simpletextgenerator.models import job

Expand Down
4 changes: 2 additions & 2 deletions simpletextgenerator/models/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from dataclasses import dataclass
from typing import IO
import chevron

import logging
import chevron

logger = logging.getLogger("ui")

Expand Down
4 changes: 2 additions & 2 deletions simpletextgenerator/models/job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from simpletextgenerator.models import config, state

import logging

from simpletextgenerator.models import config, state

logger = logging.getLogger("ui")


Expand Down
3 changes: 2 additions & 1 deletion simpletextgenerator/models/state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from dataclasses import dataclass
from typing import IO

import chevron
import logging

logger = logging.getLogger("ui")

Expand Down
1 change: 1 addition & 0 deletions simpletextgenerator/models/worklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class WorkItem:
"""
Interface for the 2 classes below
"""

def __init__(self, items_to_complete: int):
self._items_to_complete = items_to_complete

Expand Down
9 changes: 5 additions & 4 deletions simpletextgenerator/training.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import logging
import os

from textgenrnn import textgenrnn

from simpletextgenerator.jobs_util import resource_path
from simpletextgenerator.logging_setup import setup_logging
from simpletextgenerator.models.job import Job
from simpletextgenerator.training_status import TrainingStatus



class Train:
def __init__(self, job: Job, logger):
self.logger = logger
Expand Down Expand Up @@ -85,7 +84,8 @@ def save_final_model(self):
def generate_final_text(self):
self.logger.info("Generating final text")
for temperature in self.job.config.temperatures_to_generate:
generated = self.textgen.generate(n=self.job.config.items_to_generate_at_end, return_as_list=True, temperature=temperature)
generated = self.textgen.generate(n=self.job.config.items_to_generate_at_end, return_as_list=True,
temperature=temperature)
self.save_lines_to_file("last", temperature, generated)

def save_model(self, model_name: str) -> None:
Expand All @@ -109,7 +109,8 @@ def generate_text(self, i) -> None:
if (i % self.job.config.generate_every_n_generations) == 0:
for temperature in self.job.config.temperatures_to_generate:
try:
generated = self.textgen.generate(n=self.job.config.items_to_generate_each_generation, return_as_list=True, temperature=temperature)
generated = self.textgen.generate(n=self.job.config.items_to_generate_each_generation,
return_as_list=True, temperature=temperature)
except KeyError:
continue
self.save_lines_to_file(i * self.job.config.generate_every_n_generations, temperature, generated)
Expand Down
7 changes: 3 additions & 4 deletions simpletextgenerator/ui/archive_delete.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import logging
import os
import shutil
import tkinter as tk

import logging
from tkinter.messagebox import askyesno

logger = logging.getLogger("ui")
Expand Down Expand Up @@ -40,7 +39,8 @@ def option_selected(self, selected_value):
def archive_project(self):
if self.selected_project_name.get() == '' or self.selected_project_name.get() == 'Select a project':
return
shutil.move(f"projects/{self.selected_project_name.get()}", f"projects/archive/{self.selected_project_name.get()}")
shutil.move(f"projects/{self.selected_project_name.get()}",
f"projects/archive/{self.selected_project_name.get()}")
self.selected_project_name.set("Select a project")
self.destroy_window()

Expand All @@ -54,7 +54,6 @@ def delete_project(self):
return
self.archive_delete_window.lift()


def draw_archive_delete_window(self):
if self.archive_delete_window is not None:
self.archive_delete_window = None
Expand Down
9 changes: 6 additions & 3 deletions simpletextgenerator/ui/edit_job.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import logging
import os
import tkinter as tk
from pathlib import Path
from shutil import copyfile
from tkinter import filedialog
import tkinter as tk

import chevron
from pathlib import Path

from simpletextgenerator.jobs_util import create_job, resource_path
from simpletextgenerator.models.config import Config
from simpletextgenerator.training_status import TrainingStatus

import logging
logger = logging.getLogger("ui")


def draw_edit_existing_job_window():
edit_existing_job_window = EditJobWindow()
edit_existing_job_window.draw_edit_existing_job_window()
Expand Down
14 changes: 7 additions & 7 deletions simpletextgenerator/ui/generating_only_job.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import logging
import os
import chevron
import tkinter as tk
from tkinter import filedialog
from pathlib import Path
from os.path import splitext
from tkinter import messagebox
from pathlib import Path
from shutil import copyfile
from tkinter import filedialog
from tkinter import messagebox

import chevron

from simpletextgenerator.jobs_util import resource_path
from simpletextgenerator.models.config import Config
from simpletextgenerator.training_status import TrainingStatus

import logging

logger = logging.getLogger("ui")


Expand Down Expand Up @@ -193,7 +193,7 @@ def create_state_file(self, path):
f.write(self.render_state_file_text())

def copy_training_file(self, project_path):
#todo delete
# todo delete
pass
# copyfile(self.training_file_origin_path, f"./{project_path}/{self.training_file}")

Expand Down
3 changes: 1 addition & 2 deletions simpletextgenerator/ui/menu.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import logging
import tkinter as tk

from simpletextgenerator.ui import new_job, edit_job, training, archive_delete, generating_only_job

import logging

logger = logging.getLogger("ui")


Expand Down
12 changes: 6 additions & 6 deletions simpletextgenerator/ui/new_job.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import logging
import os
import chevron
import tkinter as tk
from tkinter import filedialog
from pathlib import Path
from os.path import splitext
from tkinter import messagebox
from pathlib import Path
from shutil import copyfile
from tkinter import filedialog
from tkinter import messagebox

import chevron

from simpletextgenerator.jobs_util import resource_path
from simpletextgenerator.models.config import Config
from simpletextgenerator.training_status import TrainingStatus

import logging

logger = logging.getLogger("ui")


Expand Down
5 changes: 2 additions & 3 deletions simpletextgenerator/ui/training.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import asyncio
import contextlib
import logging
import os
import re
import threading
import tkinter
import tkinter as tk
from datetime import datetime
from tkinter import ttk, LEFT, BOTTOM, RIGHT, TOP
from queue import Queue
from tkinter import ttk, LEFT
from tkinter.scrolledtext import ScrolledText

import logging

from simpletextgenerator.utility.running_mean import RunningMean

logger = logging.getLogger("ui")
Expand Down
1 change: 0 additions & 1 deletion tests/ui/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ def test_get_percentage_bar2():
training_window = TrainingWindow(None, None, None)
result = training_window.get_percentage_bar2("80%|████████ | 4/5 [00:13<00:03, 3.12it/s]")
assert result == "80"

1 change: 1 addition & 0 deletions tests/utility/test_running_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_3_average():

assert running_mean.mean() == 2


def test_10_average():
running_mean = RunningMean(10)

Expand Down

0 comments on commit c8ea568

Please sign in to comment.