Skip to content

Commit 8fb500a

Browse files
committed
refactor: remove requests and python-dotenv to reduce size
1 parent 45d0212 commit 8fb500a

File tree

3 files changed

+87
-33
lines changed

3 files changed

+87
-33
lines changed

requirements.txt

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
psutil~=6.0.0
2-
requests~=2.32.3
3-
numpy<3.0.0
4-
torch~=2.4.0
5-
sentencepiece~=0.2.0
1+
# System Monitoring
62
PyYAML~=6.0.2
3+
psutil~=6.0.0
74
pynvml~=11.5.3
5+
# GUI Library
86
PySide6~=6.7.2
9-
python-dotenv~=1.0.1
7+
# llama.cpp tools (external)
108
safetensors~=0.4.4
9+
numpy<3.0.0
10+
torch~=2.4.0
11+
sentencepiece~=0.2.0
12+
# PyPI build
1113
setuptools~=74.0.0
14+
# HuggingFace Download/Upload
1215
huggingface-hub~=0.24.6
16+
# AutoFP8 (external)
1317
transformers~=4.44.2
18+
# Local Server
1419
fastapi~=0.112.2
1520
uvicorn~=0.30.6

src/AutoGGUF.py

+52-12
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import json
33
import re
44
import shutil
5+
import urllib.request
6+
import urllib.error
57
from datetime import datetime
68
from functools import partial
79
from typing import Any, Dict, List, Tuple
810

9-
import requests
1011
from PySide6.QtCore import *
1112
from PySide6.QtGui import *
1213
from PySide6.QtWidgets import *
13-
from dotenv import load_dotenv
1414

1515
import lora_conversion
1616
import presets
@@ -44,7 +44,7 @@ def __init__(self, args: List[str]) -> None:
4444
self.setGeometry(100, 100, width, height)
4545
self.setWindowFlag(Qt.FramelessWindowHint)
4646

47-
load_dotenv() # Loads the .env file
47+
self.load_dotenv() # Loads the .env file
4848

4949
# Configuration
5050
self.model_dir_name = os.environ.get("AUTOGGUF_MODEL_DIR_NAME", "models")
@@ -805,6 +805,41 @@ def __init__(self, args: List[str]) -> None:
805805

806806
self.logger.info(AUTOGGUF_INITIALIZATION_COMPLETE)
807807

808+
def load_dotenv(self):
809+
if not os.path.isfile(".env"):
810+
self.logger.warning(".env file not found.")
811+
return
812+
813+
try:
814+
with open(".env") as f:
815+
for line in f:
816+
# Strip leading/trailing whitespace
817+
line = line.strip()
818+
819+
# Ignore comments and empty lines
820+
if not line or line.startswith("#"):
821+
continue
822+
823+
# Match key-value pairs (unquoted and quoted values)
824+
match = re.match(r"^([^=]+)=(.*)$", line)
825+
if not match:
826+
self.logger.warning(f"Could not parse line: {line}")
827+
continue
828+
829+
key, value = match.groups()
830+
831+
# Remove any surrounding quotes from the value
832+
if value.startswith(("'", '"')) and value.endswith(("'", '"')):
833+
value = value[1:-1]
834+
835+
# Decode escape sequences
836+
value = bytes(value, "utf-8").decode("unicode_escape")
837+
838+
# Set the environment variable
839+
os.environ[key.strip()] = value.strip()
840+
except Exception as e:
841+
self.logger.error(f"Error loading .env: {e}")
842+
808843
def load_plugins(self) -> Dict[str, Dict[str, Any]]:
809844
plugins = {}
810845
plugin_dir = "plugins"
@@ -881,17 +916,22 @@ def apply_plugins(self) -> None:
881916

882917
def check_for_updates(self) -> None:
883918
try:
884-
response = requests.get(
885-
"https://api.github.com/repos/leafspark/AutoGGUF/releases/latest"
886-
)
887-
response.raise_for_status() # Raise an exception for bad status codes
919+
url = "https://api.github.com/repos/leafspark/AutoGGUF/releases/latest"
920+
req = urllib.request.Request(url)
921+
922+
with urllib.request.urlopen(req) as response:
923+
if response.status != 200:
924+
raise urllib.error.HTTPError(
925+
url, response.status, "HTTP Error", response.headers, None
926+
)
927+
928+
latest_release = json.loads(response.read().decode("utf-8"))
929+
latest_version = latest_release["tag_name"].replace("v", "")
888930

889-
latest_release = response.json()
890-
latest_version = latest_release["tag_name"].replace("v", "")
931+
if latest_version > AUTOGGUF_VERSION.replace("v", ""):
932+
self.prompt_for_update(latest_release)
891933

892-
if latest_version > AUTOGGUF_VERSION.replace("v", ""):
893-
self.prompt_for_update(latest_release)
894-
except requests.exceptions.RequestException as e:
934+
except urllib.error.URLError as e:
895935
self.logger.warning(f"{ERROR_CHECKING_FOR_UPDATES} {e}")
896936

897937
def prompt_for_update(self, release) -> None:

src/DownloadThread.py

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
2+
import urllib.request
3+
import urllib.error
24
import zipfile
3-
4-
import requests
55
from PySide6.QtCore import QThread, Signal
66

77

@@ -17,19 +17,28 @@ def __init__(self, url, save_path) -> None:
1717

1818
def run(self) -> None:
1919
try:
20-
response = requests.get(self.url, stream=True)
21-
response.raise_for_status()
22-
total_size = int(response.headers.get("content-length", 0))
23-
block_size = 8192
24-
downloaded = 0
25-
26-
with open(self.save_path, "wb") as file:
27-
for data in response.iter_content(block_size):
28-
size = file.write(data)
29-
downloaded += size
30-
if total_size:
31-
progress = int((downloaded / total_size) * 100)
32-
self.progress_signal.emit(progress)
20+
req = urllib.request.Request(self.url)
21+
22+
with urllib.request.urlopen(req) as response:
23+
if response.status != 200:
24+
raise urllib.error.HTTPError(
25+
self.url, response.status, "HTTP Error", response.headers, None
26+
)
27+
28+
total_size = int(response.headers.get("Content-Length", 0))
29+
block_size = 8192
30+
downloaded = 0
31+
32+
with open(self.save_path, "wb") as file:
33+
while True:
34+
data = response.read(block_size)
35+
if not data:
36+
break
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)
3342

3443
# Extract the downloaded zip file
3544
extract_dir = os.path.splitext(self.save_path)[0]

0 commit comments

Comments
 (0)