Skip to content

Commit fa51f7c

Browse files
committed
style: format code with Black
1 parent 2dc5bd9 commit fa51f7c

21 files changed

+8226
-6933
lines changed

src/AutoGGUF.py

+26-17
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self):
3131

3232
self.logger.info(INITIALIZING_AUTOGGUF)
3333
self.setWindowTitle(WINDOW_TITLE)
34-
self.setWindowIcon(QIcon(resource_path("assets/favicon.ico")))
34+
self.setWindowIcon(QIcon(resource_path("assets/favicon.ico")))
3535
self.setGeometry(100, 100, 1600, 1200)
3636

3737
ensure_directory(os.path.abspath("quantized_models"))
@@ -171,7 +171,7 @@ def __init__(self):
171171
"Q5_K_S",
172172
"Q5_K_M",
173173
"Q6_K",
174-
"Q8_0",
174+
"Q8_0",
175175
"Q4_0",
176176
"Q4_1",
177177
"Q5_0",
@@ -180,7 +180,7 @@ def __init__(self):
180180
"Q4_0_4_8",
181181
"Q4_0_8_8",
182182
"BF16",
183-
"F16",
183+
"F16",
184184
"F32",
185185
"COPY",
186186
]
@@ -452,8 +452,13 @@ def __init__(self):
452452
# Output Type Dropdown
453453
self.lora_output_type_combo = QComboBox()
454454
self.lora_output_type_combo.addItems(["GGML", "GGUF"])
455-
self.lora_output_type_combo.currentIndexChanged.connect(self.update_base_model_visibility)
456-
lora_layout.addRow(self.create_label(OUTPUT_TYPE, SELECT_OUTPUT_TYPE), self.lora_output_type_combo)
455+
self.lora_output_type_combo.currentIndexChanged.connect(
456+
self.update_base_model_visibility
457+
)
458+
lora_layout.addRow(
459+
self.create_label(OUTPUT_TYPE, SELECT_OUTPUT_TYPE),
460+
self.lora_output_type_combo,
461+
)
457462

458463
# Base Model Path (initially hidden)
459464
self.base_model_label = self.create_label(BASE_MODEL, SELECT_BASE_MODEL_FILE)
@@ -471,7 +476,9 @@ def __init__(self):
471476
wrapper_layout = QHBoxLayout(self.base_model_wrapper)
472477
wrapper_layout.addWidget(self.base_model_label)
473478
wrapper_layout.addWidget(self.base_model_widget, 1) # Give it a stretch factor
474-
wrapper_layout.setContentsMargins(0, 0, 0, 0) # Remove margins for better alignment
479+
wrapper_layout.setContentsMargins(
480+
0, 0, 0, 0
481+
) # Remove margins for better alignment
475482

476483
# Add the wrapper to the layout
477484
lora_layout.addRow(self.base_model_wrapper)
@@ -545,7 +552,7 @@ def __init__(self):
545552
# Modify the task list to support right-click menu
546553
self.task_list.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
547554
self.task_list.customContextMenuRequested.connect(self.show_task_context_menu)
548-
555+
549556
# Set inital state
550557
self.update_base_model_visibility(self.lora_output_type_combo.currentIndex())
551558

@@ -1200,19 +1207,19 @@ def delete_task(self, item):
12001207
if reply == QMessageBox.StandardButton.Yes:
12011208
# Retrieve the task_item before removing it from the list
12021209
task_item = self.task_list.itemWidget(item)
1203-
1210+
12041211
# Remove the item from the list
12051212
row = self.task_list.row(item)
12061213
self.task_list.takeItem(row)
1207-
1214+
12081215
# If the task is still running, terminate it
12091216
if task_item and task_item.log_file:
12101217
for thread in self.quant_threads:
12111218
if thread.log_file == task_item.log_file:
12121219
thread.terminate()
12131220
self.quant_threads.remove(thread)
1214-
break
1215-
1221+
break
1222+
12161223
# Delete the task_item widget
12171224
if task_item:
12181225
task_item.deleteLater()
@@ -1395,7 +1402,7 @@ def quantize_model(self):
13951402
override_string = entry.get_override_string(
13961403
model_name=model_name,
13971404
quant_type=quant_type,
1398-
output_path=output_path
1405+
output_path=output_path,
13991406
)
14001407
if override_string:
14011408
command.extend(["--override-kv", override_string])
@@ -1413,7 +1420,7 @@ def quantize_model(self):
14131420
log_file = os.path.join(
14141421
logs_path, f"{model_name}_{timestamp}_{quant_type}.log"
14151422
)
1416-
1423+
14171424
# Log quant command
14181425
command_str = " ".join(command)
14191426
self.logger.info(f"{QUANTIZATION_COMMAND}: {command_str}")
@@ -1430,7 +1437,9 @@ def quantize_model(self):
14301437
self.task_list.setItemWidget(list_item, task_item)
14311438

14321439
# Connect the output signal to the new progress parsing function
1433-
thread.output_signal.connect(lambda line: self.parse_progress(line, task_item))
1440+
thread.output_signal.connect(
1441+
lambda line: self.parse_progress(line, task_item)
1442+
)
14341443
thread.status_signal.connect(task_item.update_status)
14351444
thread.finished_signal.connect(lambda: self.task_finished(thread))
14361445
thread.error_signal.connect(lambda err: self.handle_error(err, task_item))
@@ -1556,7 +1565,7 @@ def generate_imatrix(self):
15561565

15571566
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
15581567
log_file = os.path.join(self.logs_input.text(), f"imatrix_{timestamp}.log")
1559-
1568+
15601569
# Log command
15611570
command_str = " ".join(command)
15621571
self.logger.info(f"{IMATRIX_GENERATION_COMMAND}: {command_str}")
@@ -1580,7 +1589,7 @@ def generate_imatrix(self):
15801589
except Exception as e:
15811590
self.show_error(ERROR_STARTING_IMATRIX_GENERATION.format(str(e)))
15821591
self.logger.info(IMATRIX_GENERATION_TASK_STARTED)
1583-
1592+
15841593
def show_error(self, message):
15851594
self.logger.error(ERROR_MESSAGE.format(message))
15861595
QMessageBox.critical(self, ERROR, message)
@@ -1617,4 +1626,4 @@ def closeEvent(self, event: QCloseEvent):
16171626
app = QApplication(sys.argv)
16181627
window = AutoGGUF()
16191628
window.show()
1620-
sys.exit(app.exec())
1629+
sys.exit(app.exec())

src/DownloadThread.py

+55-54
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
1-
from PyQt6.QtWidgets import *
2-
from PyQt6.QtCore import *
3-
from PyQt6.QtGui import *
4-
import os
5-
import sys
6-
import psutil
7-
import subprocess
8-
import time
9-
import signal
10-
import json
11-
import platform
12-
import requests
13-
import zipfile
14-
from datetime import datetime
15-
16-
class DownloadThread(QThread):
17-
progress_signal = pyqtSignal(int)
18-
finished_signal = pyqtSignal(str)
19-
error_signal = pyqtSignal(str)
20-
21-
def __init__(self, url, save_path):
22-
super().__init__()
23-
self.url = url
24-
self.save_path = save_path
25-
26-
def run(self):
27-
try:
28-
response = requests.get(self.url, stream=True)
29-
response.raise_for_status()
30-
total_size = int(response.headers.get('content-length', 0))
31-
block_size = 8192
32-
downloaded = 0
33-
34-
with open(self.save_path, 'wb') as file:
35-
for data in response.iter_content(block_size):
36-
size = file.write(data)
37-
downloaded += size
38-
if total_size:
39-
progress = int((downloaded / total_size) * 100)
40-
self.progress_signal.emit(progress)
41-
42-
# Extract the downloaded zip file
43-
extract_dir = os.path.splitext(self.save_path)[0]
44-
with zipfile.ZipFile(self.save_path, 'r') as zip_ref:
45-
zip_ref.extractall(extract_dir)
46-
47-
# Remove the zip file after extraction
48-
os.remove(self.save_path)
49-
50-
self.finished_signal.emit(extract_dir)
51-
except Exception as e:
52-
self.error_signal.emit(str(e))
53-
if os.path.exists(self.save_path):
54-
os.remove(self.save_path)
1+
from PyQt6.QtWidgets import *
2+
from PyQt6.QtCore import *
3+
from PyQt6.QtGui import *
4+
import os
5+
import sys
6+
import psutil
7+
import subprocess
8+
import time
9+
import signal
10+
import json
11+
import platform
12+
import requests
13+
import zipfile
14+
from datetime import datetime
15+
16+
17+
class DownloadThread(QThread):
18+
progress_signal = pyqtSignal(int)
19+
finished_signal = pyqtSignal(str)
20+
error_signal = pyqtSignal(str)
21+
22+
def __init__(self, url, save_path):
23+
super().__init__()
24+
self.url = url
25+
self.save_path = save_path
26+
27+
def run(self):
28+
try:
29+
response = requests.get(self.url, stream=True)
30+
response.raise_for_status()
31+
total_size = int(response.headers.get("content-length", 0))
32+
block_size = 8192
33+
downloaded = 0
34+
35+
with open(self.save_path, "wb") as file:
36+
for data in response.iter_content(block_size):
37+
size = file.write(data)
38+
downloaded += size
39+
if total_size:
40+
progress = int((downloaded / total_size) * 100)
41+
self.progress_signal.emit(progress)
42+
43+
# Extract the downloaded zip file
44+
extract_dir = os.path.splitext(self.save_path)[0]
45+
with zipfile.ZipFile(self.save_path, "r") as zip_ref:
46+
zip_ref.extractall(extract_dir)
47+
48+
# Remove the zip file after extraction
49+
os.remove(self.save_path)
50+
51+
self.finished_signal.emit(extract_dir)
52+
except Exception as e:
53+
self.error_signal.emit(str(e))
54+
if os.path.exists(self.save_path):
55+
os.remove(self.save_path)

0 commit comments

Comments
 (0)