ollamadiffuser 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ollamadiffuser/__init__.py +0 -0
- ollamadiffuser/__main__.py +50 -0
- ollamadiffuser/api/__init__.py +0 -0
- ollamadiffuser/api/server.py +297 -0
- ollamadiffuser/cli/__init__.py +0 -0
- ollamadiffuser/cli/main.py +597 -0
- ollamadiffuser/core/__init__.py +0 -0
- ollamadiffuser/core/config/__init__.py +0 -0
- ollamadiffuser/core/config/settings.py +137 -0
- ollamadiffuser/core/inference/__init__.py +0 -0
- ollamadiffuser/core/inference/engine.py +926 -0
- ollamadiffuser/core/models/__init__.py +0 -0
- ollamadiffuser/core/models/manager.py +436 -0
- ollamadiffuser/core/utils/__init__.py +3 -0
- ollamadiffuser/core/utils/download_utils.py +356 -0
- ollamadiffuser/core/utils/lora_manager.py +390 -0
- ollamadiffuser/ui/__init__.py +0 -0
- ollamadiffuser/ui/templates/index.html +496 -0
- ollamadiffuser/ui/web.py +278 -0
- ollamadiffuser/utils/__init__.py +0 -0
- ollamadiffuser-1.0.0.dist-info/METADATA +493 -0
- ollamadiffuser-1.0.0.dist-info/RECORD +26 -0
- ollamadiffuser-1.0.0.dist-info/WHEEL +5 -0
- ollamadiffuser-1.0.0.dist-info/entry_points.txt +2 -0
- ollamadiffuser-1.0.0.dist-info/licenses/LICENSE +21 -0
- ollamadiffuser-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Dict, Any, Optional
|
|
4
|
+
import json
|
|
5
|
+
import logging
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class ModelConfig:
|
|
12
|
+
"""Configuration for a single model"""
|
|
13
|
+
name: str
|
|
14
|
+
path: str
|
|
15
|
+
model_type: str # "sd15", "sdxl", "sd3", "flux", etc.
|
|
16
|
+
variant: Optional[str] = None # "fp16", "fp32", etc.
|
|
17
|
+
components: Optional[Dict[str, str]] = None # LoRA, VAE, etc.
|
|
18
|
+
parameters: Optional[Dict[str, Any]] = None # default generation parameters
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class ServerConfig:
|
|
22
|
+
"""Server configuration"""
|
|
23
|
+
host: str = "localhost"
|
|
24
|
+
port: int = 8000
|
|
25
|
+
max_queue_size: int = 100
|
|
26
|
+
timeout: int = 600
|
|
27
|
+
enable_cors: bool = True
|
|
28
|
+
|
|
29
|
+
class Settings:
|
|
30
|
+
"""Global application settings"""
|
|
31
|
+
|
|
32
|
+
def __init__(self):
|
|
33
|
+
self.config_dir = Path.home() / ".ollamadiffuser"
|
|
34
|
+
self.models_dir = self.config_dir / "models"
|
|
35
|
+
self.cache_dir = self.config_dir / "cache"
|
|
36
|
+
self.config_file = self.config_dir / "config.json"
|
|
37
|
+
|
|
38
|
+
# Ensure directories exist
|
|
39
|
+
self.config_dir.mkdir(exist_ok=True)
|
|
40
|
+
self.models_dir.mkdir(exist_ok=True)
|
|
41
|
+
self.cache_dir.mkdir(exist_ok=True)
|
|
42
|
+
|
|
43
|
+
# Default configuration
|
|
44
|
+
self.server = ServerConfig()
|
|
45
|
+
self.models: Dict[str, ModelConfig] = {}
|
|
46
|
+
self.current_model: Optional[str] = None
|
|
47
|
+
self.hf_token: Optional[str] = os.environ.get('HF_TOKEN')
|
|
48
|
+
|
|
49
|
+
# Load configuration file
|
|
50
|
+
self.load_config()
|
|
51
|
+
|
|
52
|
+
def load_config(self):
|
|
53
|
+
"""Load settings from configuration file"""
|
|
54
|
+
if self.config_file.exists():
|
|
55
|
+
try:
|
|
56
|
+
with open(self.config_file, 'r', encoding='utf-8') as f:
|
|
57
|
+
config_data = json.load(f)
|
|
58
|
+
|
|
59
|
+
# Load server configuration
|
|
60
|
+
if 'server' in config_data:
|
|
61
|
+
server_data = config_data['server']
|
|
62
|
+
self.server = ServerConfig(**server_data)
|
|
63
|
+
|
|
64
|
+
# Load model configuration
|
|
65
|
+
if 'models' in config_data:
|
|
66
|
+
self.models = {
|
|
67
|
+
name: ModelConfig(**model_data)
|
|
68
|
+
for name, model_data in config_data['models'].items()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
self.current_model = config_data.get('current_model')
|
|
72
|
+
|
|
73
|
+
logger.info(f"Configuration file loaded: {self.config_file}")
|
|
74
|
+
|
|
75
|
+
except Exception as e:
|
|
76
|
+
logger.error(f"Failed to load configuration file: {e}")
|
|
77
|
+
|
|
78
|
+
def save_config(self):
|
|
79
|
+
"""Save settings to configuration file"""
|
|
80
|
+
try:
|
|
81
|
+
config_data = {
|
|
82
|
+
'server': {
|
|
83
|
+
'host': self.server.host,
|
|
84
|
+
'port': self.server.port,
|
|
85
|
+
'max_queue_size': self.server.max_queue_size,
|
|
86
|
+
'timeout': self.server.timeout,
|
|
87
|
+
'enable_cors': self.server.enable_cors
|
|
88
|
+
},
|
|
89
|
+
'models': {
|
|
90
|
+
name: {
|
|
91
|
+
'name': model.name,
|
|
92
|
+
'path': model.path,
|
|
93
|
+
'model_type': model.model_type,
|
|
94
|
+
'variant': model.variant,
|
|
95
|
+
'components': model.components,
|
|
96
|
+
'parameters': model.parameters
|
|
97
|
+
}
|
|
98
|
+
for name, model in self.models.items()
|
|
99
|
+
},
|
|
100
|
+
'current_model': self.current_model
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
with open(self.config_file, 'w', encoding='utf-8') as f:
|
|
104
|
+
json.dump(config_data, f, indent=2, ensure_ascii=False)
|
|
105
|
+
|
|
106
|
+
logger.info(f"Configuration saved to: {self.config_file}")
|
|
107
|
+
|
|
108
|
+
except Exception as e:
|
|
109
|
+
logger.error(f"Failed to save configuration file: {e}")
|
|
110
|
+
|
|
111
|
+
def add_model(self, model_config: ModelConfig):
|
|
112
|
+
"""Add model configuration"""
|
|
113
|
+
self.models[model_config.name] = model_config
|
|
114
|
+
self.save_config()
|
|
115
|
+
|
|
116
|
+
def remove_model(self, model_name: str):
|
|
117
|
+
"""Remove model configuration"""
|
|
118
|
+
if model_name in self.models:
|
|
119
|
+
del self.models[model_name]
|
|
120
|
+
if self.current_model == model_name:
|
|
121
|
+
self.current_model = None
|
|
122
|
+
self.save_config()
|
|
123
|
+
|
|
124
|
+
def set_current_model(self, model_name: str):
|
|
125
|
+
"""Set current model to use"""
|
|
126
|
+
if model_name in self.models:
|
|
127
|
+
self.current_model = model_name
|
|
128
|
+
self.save_config()
|
|
129
|
+
else:
|
|
130
|
+
raise ValueError(f"Model '{model_name}' does not exist")
|
|
131
|
+
|
|
132
|
+
def get_model_path(self, model_name: str) -> Path:
|
|
133
|
+
"""Get storage path for model"""
|
|
134
|
+
return self.models_dir / model_name
|
|
135
|
+
|
|
136
|
+
# Global settings instance
|
|
137
|
+
settings = Settings()
|
|
File without changes
|