Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions .github/workflows/mega-linter.yml

This file was deleted.

73 changes: 0 additions & 73 deletions .mega-linter.yml

This file was deleted.

15 changes: 6 additions & 9 deletions api_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ def create_session():
retry = Retry(
total=5, # Maximum number of retries
backoff_factor=0.5, # Exponential backoff factor (sleep longer between retries)
status_forcelist=[500, 502, 503, 504] # HTTP status codes to retry on
status_forcelist=[500, 502, 503, 504], # HTTP status codes to retry on
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
session.mount("http://", adapter)
session.mount("https://", adapter)

# Proxy configuration
if config.getboolean('Proxy', 'use_proxy'):
proxies = {
'http': config['Proxy']['http'],
'https': config['Proxy']['https']
}
if config.getboolean("Proxy", "use_proxy"):
proxies = {"http": config["Proxy"]["http"], "https": config["Proxy"]["https"]}
session.proxies.update(proxies)
logger.info(f"Using proxy: {proxies}")
else:
logger.info("Not using a proxy.")

return session
return session
6 changes: 4 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[HuggingFace]
api_token_alias = Desktop
rate_limit_delay = 1
api_token = mkdhyYZxh|JwYkrWWGsikRTgNYzMwZ~hWI{S
rate_limit_delay = 1.0
org =
repo =

[Zip]
default_zip_name = my_archive
Expand Down
95 changes: 68 additions & 27 deletions config_dialog.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,69 @@
import logging
from PyQt6.QtWidgets import (QWidget, QLabel, QLineEdit, QPushButton,
QVBoxLayout, QHBoxLayout, QCheckBox, QMessageBox)
from PyQt6.QtWidgets import (
QWidget,
QLabel,
QLineEdit,
QPushButton,
QVBoxLayout,
QHBoxLayout,
QCheckBox,
QMessageBox,
)
from PyQt6.QtCore import Qt
from custom_exceptions import ConfigError # Import ConfigError
from config_manager import config, save_config
from config_manager import (
config,
set_api_token,
get_api_token,
get_rate_limit_delay,
set_rate_limit_delay, # Make sure this is imported
set_proxy,
get_proxy,
# save_config # You don't really need to import save_config directly in the ConfigDialog
)


logger = logging.getLogger(__name__)


def obfuscate_token(token):
"""A simple obfuscation function (DO NOT RELY ON THIS FOR SECURITY)."""
obfuscated = ''.join([chr(ord(c) + 5) for c in token]) # Shift each character by 5
obfuscated = "".join([chr(ord(c) + 5) for c in token]) # Shift each character by 5
return obfuscated


def deobfuscate_token(obfuscated):
"""Reverses the obfuscation (DO NOT RELY ON THIS FOR SECURITY)."""
original = ''.join([chr(ord(c) - 5) for c in obfuscated])
original = "".join([chr(ord(c) - 5) for c in obfuscated])
return original


class ConfigDialog(QWidget):
"""Dialog for configuring settings."""

def __init__(self):
"""Initializes the configuration dialog."""
super().__init__()
self.setWindowTitle("Configuration")
self.init_ui()
self.load_config_values()

def init_ui(self):
"""Initializes the user interface elements and layout."""
# --- API Token Section ---
self.api_token_label = QLabel("Hugging Face API Token:")
self.api_token_input = QLineEdit() # No default
self.api_token_input.setEchoMode(QLineEdit.Password) # Mask the token
self.api_token_input.setEchoMode(QLineEdit.EchoMode.Password) # Mask the token

# --- Proxy Section ---
self.use_proxy_checkbox = QCheckBox("Use Proxy")
self.use_proxy_checkbox.setChecked(config.getboolean('Proxy', 'use_proxy'))
# self.use_proxy_checkbox.setChecked(config.getboolean("Proxy", "use_proxy"))
self.http_proxy_label = QLabel("HTTP Proxy:")
self.http_proxy_input = QLineEdit(config['Proxy']['http'])
self.http_proxy_input = QLineEdit() # No default - filled from load
self.https_proxy_label = QLabel("HTTPS Proxy:")
self.https_proxy_input = QLineEdit(config['Proxy']['https'])
self.https_proxy_input = QLineEdit() # No default - filled from load
self.rate_limit_label = QLabel("Rate Limit Delay (seconds):")
self.rate_limit_input = QLineEdit(config['HuggingFace']['rate_limit_delay'])
self.rate_limit_input = QLineEdit()

# --- Buttons ---
self.save_button = QPushButton("Save")
Expand Down Expand Up @@ -76,6 +98,20 @@ def __init__(self):
self.save_button.clicked.connect(self.save_config)
self.cancel_button.clicked.connect(self.close)

def load_config_values(self):
"""Loads configuration values from the config manager and populates the UI."""
# Load API token
self.api_token_input.setText(get_api_token() or "") # Load the API token
# Load Proxy settings
proxy_settings = get_proxy()
self.use_proxy_checkbox.setChecked(
proxy_settings.get("use_proxy", "False") == "True"
)
self.http_proxy_input.setText(proxy_settings.get("http", ""))
self.https_proxy_input.setText(proxy_settings.get("https", ""))
# Load Rate limit delay
self.rate_limit_input.setText(str(get_rate_limit_delay()))

def save_config(self):
"""Saves the configuration settings."""
api_token = self.api_token_input.text()
Expand All @@ -89,22 +125,27 @@ def save_config(self):
QMessageBox.critical(self, "Error", str(e))
return

# Obfuscate the API token
obfuscated_token = obfuscate_token(api_token)

# Save proxy settings
config['Proxy']['use_proxy'] = str(self.use_proxy_checkbox.isChecked())
config['Proxy']['http'] = self.http_proxy_input.text()
config['Proxy']['https'] = self.https_proxy_input.text()
config['HuggingFace']['rate_limit_delay'] = str(rate_limit_delay) # Store as string
config['HuggingFace']['api_token'] = obfuscated_token # Obfuscated API token

# Write to config file
# Save the config values
try:
if save_config(): # Call save_config and check for success
QMessageBox.information(self, "Success", "Configuration saved successfully.")
self.close()
else:
QMessageBox.critical(self, "Error", "Failed to save configuration.")
# Set API token
set_api_token(api_token) # Store the api token in the manager

# Save proxy settings
proxy_settings = {
"use_proxy": str(self.use_proxy_checkbox.isChecked()),
"http": self.http_proxy_input.text(),
"https": self.https_proxy_input.text(),
}
set_proxy(proxy_settings) # save proxy settings
# Save rate limit
# config["HuggingFace"]["rate_limit_delay"] = str(rate_limit_delay)
set_rate_limit_delay(rate_limit_delay)
QMessageBox.information(
self, "Success", "Configuration saved successfully."
)
self.close()
except ConfigError as e:
QMessageBox.critical(self, "Error", f"Failed to save configuration: {e}")
QMessageBox.critical(self, "Error", f"Failed to save configuration: {e}")
except Exception as e:
# Catch any unexpected errors
QMessageBox.critical(self, "Error", f"An unexpected error occurred: {e}")
Loading