Skip to content

Commit 4f3d4a0

Browse files
committed
Removed train.py and training completely
1 parent cae589e commit 4f3d4a0

4 files changed

Lines changed: 16 additions & 33 deletions

File tree

scripts/classify_process_file.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def load_index_and_labels():
4949
print(f"[!] An error occurred while loading index or labels: {e}")
5050
return False
5151

52-
def classify_file(text, filename, allow_generation=True, TRAIN=False, retries=0):
52+
def classify_file(text, filename, allow_generation=True, retries=0):
5353
# --- SAFETY NET: MAX RETRIES ---
5454
MAX_RETRIES = 3
5555

@@ -164,7 +164,7 @@ def classify_file(text, filename, allow_generation=True, TRAIN=False, retries=0)
164164
with CLASSIFICATION_LOCK:
165165
if index:
166166
retry_label, retry_sim = classify_file(
167-
text, filename, allow_generation=False, TRAIN=TRAIN, retries=retries
167+
text, filename, allow_generation=False, retries=retries
168168
)
169169
if retry_label != "Uncategorized":
170170
return retry_label, retry_sim
@@ -174,24 +174,17 @@ def classify_file(text, filename, allow_generation=True, TRAIN=False, retries=0)
174174

175175
if new_label_info and new_label_info.get("folder_label"):
176176
if create_faiss_index():
177-
load_index_and_labels()
178-
179-
if TRAIN:
180-
print(f"[∞] [TRAIN MODE] Re-checking '{filename}'...")
181-
return classify_file(
182-
text, filename, allow_generation=True, TRAIN=True, retries=retries+1
183-
)
184-
else:
185-
print(f"[1] [ONE-SHOT] Re-checking '{filename}'...")
186-
return classify_file(
187-
text, filename, allow_generation=False, TRAIN=False, retries=retries+1
188-
)
177+
load_index_and_labels()
178+
print(f"[1] [ONE-SHOT] Re-checking '{filename}'...")
179+
return classify_file(
180+
text, filename, allow_generation=allow_generation, retries=retries+1
181+
)
189182

190183
return classify_file(
191-
text, filename, allow_generation=False, TRAIN=TRAIN, retries=retries
184+
text, filename, allow_generation=False, retries=retries
192185
)
193186

194-
def process_file(file_path, testing=False, allow_generation=True, TRAIN=False):
187+
def process_file(file_path, testing=False, allow_generation=True):
195188
start_time = time.time()
196189
filename = os.path.basename(file_path)
197190

@@ -201,7 +194,7 @@ def process_file(file_path, testing=False, allow_generation=True, TRAIN=False):
201194
text = filename.replace("_", " ").replace("-", " ")
202195

203196
predicted_folder, similarity = classify_file(
204-
text, filename, allow_generation=False, TRAIN=TRAIN
197+
text, filename, allow_generation=False
205198
)
206199

207200

@@ -212,7 +205,7 @@ def process_file(file_path, testing=False, allow_generation=True, TRAIN=False):
212205

213206
if fallback_text and len(fallback_text) > 50 and fallback_text != text:
214207
new_folder, new_sim = classify_file(
215-
fallback_text, filename, allow_generation=False, TRAIN=TRAIN
208+
fallback_text, filename, allow_generation=False
216209
)
217210

218211
if new_sim > similarity:
@@ -226,7 +219,7 @@ def process_file(file_path, testing=False, allow_generation=True, TRAIN=False):
226219

227220
if allow_generation and (predicted_folder == "Uncategorized" or similarity < THRESHOLD):
228221
predicted_folder, similarity = classify_file(
229-
text, filename, allow_generation=True, TRAIN=TRAIN
222+
text, filename, allow_generation=True
230223
)
231224

232225
destination_folder = BASE_DIR / "sorted" / predicted_folder

scripts/logger.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import threading
55

66
class Logger:
7-
"""
8-
A thread-safe logger that captures all print statements and optionally saves them to a file.
9-
"""
107
def __init__(self):
118
self.terminal = sys.stdout
129
self.log_buffer = []

scripts/script.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import sys
44
from multhread import process_multiple
55
from classify_process_file import process_file, load_index_and_labels
6-
from train import train
76
from logger import setup_logger, get_logger, restore_stdout
87

98
test = True
@@ -12,7 +11,6 @@
1211
parser.add_argument("--threads", "-t", type=int, default=6, help="Maximum number of concurrent threads.")
1312
parser.add_argument("--single-thread", action="store_true", help="Run in single-threaded mode instead of multi-threaded.")
1413
parser.add_argument("--no-generation", action="store_true", help="Do not allow generation if classification fails.")
15-
parser.add_argument("--train", action="store_true", help="Enable training mode during processing.")
1614
parser.add_argument("--auto-save-logs", action="store_true", help="Automatically save logs without prompting.")
1715
parser.add_argument("--no-logs", action="store_true", help="Disable logging for this run.")
1816
args = parser.parse_args()
@@ -77,16 +75,11 @@ def prompt_save_logs(logger):
7775
print("No files to process.")
7876
else:
7977
for file_path in files:
80-
if args.train:
81-
train(files_dir, testing=test)
82-
else:
83-
process_file(file_path, testing=test, allow_generation=not args.no_generation)
78+
process_file(file_path, testing=test, allow_generation=not args.no_generation)
8479
else:
85-
if args.train:
86-
train(files_dir, testing=test)
87-
else:
88-
print(f"Processing files in directory: {files_dir} with {MAX_THREADS} threads.")
89-
process_multiple(files_dir, MAX_THREADS, testing=test, allow_generation=not args.no_generation)
80+
81+
print(f"Processing files in directory: {files_dir} with {MAX_THREADS} threads.")
82+
process_multiple(files_dir, MAX_THREADS, testing=test, allow_generation=not args.no_generation)
9083

9184
finally:
9285
# After execution, handle log saving
File renamed without changes.

0 commit comments

Comments
 (0)