Add available/hidden status for models

- Added available BOOLEAN column to models table
- Default model is marked as available
- Models specified via --model are marked as available
- Updated admin interface to show and edit availability status
- Added Status column to models table showing Available/Hidden
parent 1d85cfa6
......@@ -60,6 +60,7 @@
<th>Type</th>
<th>Path</th>
<th>VRAM (GB)</th>
<th>Status</th>
<th>Created</th>
<th>Actions</th>
</tr>
......@@ -71,9 +72,10 @@
<td>{{ model.get('type', 'N/A').title() }}</td>
<td>{{ model.get('path', 'N/A') }}</td>
<td>{{ model.get('vram_estimate', 0) }}</td>
<td><span class="status-{{ 'active' if model.get('available') else 'inactive' }}">{{ 'Available' if model.get('available') else 'Hidden' }}</span></td>
<td>{{ model.get('created_at', 'N/A')[:10] if model.get('created_at') else 'N/A' }}</td>
<td class="actions-cell">
<button onclick="editModel({{ model.get('id') }}, '{{ model.get('name') }}', '{{ model.get('type') }}', '{{ model.get('path') }}', {{ model.get('vram_estimate', 0) }})" class="btn-icon" title="Edit"><i class="fas fa-edit"></i></button>
<button onclick="editModel({{ model.get('id') }}, '{{ model.get('name') }}', '{{ model.get('type') }}', '{{ model.get('path') }}', {{ model.get('vram_estimate', 0) }}, {{ model.get('available')|lower }})" class="btn-icon" title="Edit"><i class="fas fa-edit"></i></button>
<button onclick="deleteModel({{ model.get('id') }}, '{{ model.get('name') }}')" class="btn-icon" title="Delete" style="color: #dc2626;"><i class="fas fa-trash"></i></button>
</td>
</tr>
......@@ -111,6 +113,13 @@
<input type="number" id="vram_estimate" name="vram_estimate" value="0" min="0" step="0.1">
</div>
<div class="form-group">
<label>
<input type="checkbox" id="available" name="available" checked>
Available (visible to users)
</label>
</div>
<button type="submit" class="btn">Add Model</button>
</form>
</div>
......@@ -146,6 +155,12 @@
<label for="editVram">VRAM Estimate (GB)</label>
<input type="number" id="editVram" name="vram_estimate" min="0" step="0.1" required>
</div>
<div class="form-group">
<label>
<input type="checkbox" id="editAvailable" name="available">
Available (visible to users)
</label>
</div>
</div>
<div class="modal-footer">
<button type="button" onclick="closeEditModal()" class="btn" style="background: #6b7280;">Cancel</button>
......@@ -156,12 +171,13 @@
</div>
<script>
function editModel(id, name, type, path, vram) {
function editModel(id, name, type, path, vram, available) {
document.getElementById('editModelId').value = id;
document.getElementById('editName').value = name;
document.getElementById('editType').value = type;
document.getElementById('editPath').value = path;
document.getElementById('editVram').value = vram;
document.getElementById('editAvailable').checked = available;
document.getElementById('editModelForm').action = `/admin/models/${id}/update`;
document.getElementById('editModelModal').classList.add('show');
document.body.style.overflow = 'hidden';
......
......@@ -499,6 +499,7 @@ def add_model():
model_type = request.form.get('type', '').strip()
path = request.form.get('path', '').strip()
vram_estimate = int(request.form.get('vram_estimate', 0))
available = request.form.get('available') == 'on'
if not name or not model_type or not path:
flash('All fields are required', 'error')
......@@ -523,7 +524,7 @@ def add_model():
flash(f'Error downloading model: {str(e)}', 'error')
return redirect(url_for('admin.models'))
if create_model(name, model_type, path, vram_estimate):
if create_model(name, model_type, path, vram_estimate, available):
flash('Model added successfully!', 'success')
else:
flash('Failed to add model', 'error')
......@@ -537,6 +538,7 @@ def update_model_route(model_id):
model_type = request.form.get('type', '').strip()
path = request.form.get('path', '').strip()
vram_estimate = int(request.form.get('vram_estimate', 0))
available = request.form.get('available') == 'on'
if not name or not model_type or not path:
flash('All fields are required', 'error')
......@@ -546,7 +548,7 @@ def update_model_route(model_id):
flash('Invalid model type', 'error')
return redirect(url_for('admin.models'))
if update_model(model_id, name=name, model_type=model_type, path=path, vram_estimate=vram_estimate):
if update_model(model_id, name=name, model_type=model_type, path=path, vram_estimate=vram_estimate, available=available):
flash('Model updated successfully!', 'success')
else:
flash('Failed to update model', 'error')
......
......@@ -542,6 +542,7 @@ def init_db(conn) -> None:
type VARCHAR(50) NOT NULL,
path TEXT NOT NULL UNIQUE,
vram_estimate INT DEFAULT 0,
available BOOLEAN DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
......@@ -554,11 +555,22 @@ def init_db(conn) -> None:
type TEXT NOT NULL,
path TEXT NOT NULL UNIQUE,
vram_estimate INTEGER DEFAULT 0,
available BOOLEAN DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
# Add available column if it doesn't exist
try:
if config['type'] == 'mysql':
cursor.execute('ALTER TABLE models ADD COLUMN available BOOLEAN DEFAULT 0')
else:
cursor.execute('ALTER TABLE models ADD COLUMN available BOOLEAN DEFAULT 0')
except:
# Column might already exist
pass
# Clean up duplicate models (keep only the first one for each path)
if config['type'] == 'mysql':
cursor.execute('''
......@@ -580,8 +592,8 @@ def init_db(conn) -> None:
default_model_name = 'Qwen/Qwen2.5-VL-7B-Instruct'
cursor.execute('SELECT id FROM models WHERE path = ?', (default_model_name,))
if not cursor.fetchone():
cursor.execute('INSERT INTO models (name, type, path, vram_estimate) VALUES (?, ?, ?, ?)',
('Qwen 2.5 VL 7B Instruct', 'huggingface', default_model_name, 16))
cursor.execute('INSERT INTO models (name, type, path, vram_estimate, available) VALUES (?, ?, ?, ?, ?)',
('Qwen 2.5 VL 7B Instruct', 'huggingface', default_model_name, 16, 1))
# Add data column to sessions table if it doesn't exist
try:
......@@ -1898,13 +1910,13 @@ def get_all_models() -> List[Dict[str, Any]]:
return [dict(row) for row in rows]
def create_model(name: str, model_type: str, path: str, vram_estimate: int = 0) -> bool:
def create_model(name: str, model_type: str, path: str, vram_estimate: int = 0, available: bool = False) -> bool:
"""Create a new model."""
conn = get_db_connection()
cursor = conn.cursor()
try:
cursor.execute('INSERT INTO models (name, type, path, vram_estimate) VALUES (?, ?, ?, ?)',
(name, model_type, path, vram_estimate))
cursor.execute('INSERT INTO models (name, type, path, vram_estimate, available) VALUES (?, ?, ?, ?, ?)',
(name, model_type, path, vram_estimate, 1 if available else 0))
conn.commit()
return True
except sqlite3.IntegrityError:
......@@ -1913,7 +1925,7 @@ def create_model(name: str, model_type: str, path: str, vram_estimate: int = 0)
conn.close()
def update_model(model_id: int, name: str = None, model_type: str = None, path: str = None, vram_estimate: int = None) -> bool:
def update_model(model_id: int, name: str = None, model_type: str = None, path: str = None, vram_estimate: int = None, available: bool = None) -> bool:
"""Update a model."""
conn = get_db_connection()
cursor = conn.cursor()
......@@ -1933,6 +1945,9 @@ def update_model(model_id: int, name: str = None, model_type: str = None, path:
if vram_estimate is not None:
update_fields.append('vram_estimate = ?')
params.append(vram_estimate)
if available is not None:
update_fields.append('available = ?')
params.append(1 if available else 0)
if not update_fields:
return False
......@@ -1967,7 +1982,7 @@ def get_model_by_id(model_id: int) -> Optional[Dict[str, Any]]:
return dict(row) if row else None
def ensure_model_exists(name: str, model_type: str, path: str, vram_estimate: int = 0) -> None:
def ensure_model_exists(name: str, model_type: str, path: str, vram_estimate: int = 0, available: bool = True) -> None:
"""Ensure a model exists in the database, create if not."""
conn = get_db_connection()
cursor = conn.cursor()
......@@ -1978,8 +1993,13 @@ def ensure_model_exists(name: str, model_type: str, path: str, vram_estimate: in
if not existing:
# Create the model
cursor.execute('INSERT INTO models (name, type, path, vram_estimate) VALUES (?, ?, ?, ?)',
(name, model_type, path, vram_estimate))
cursor.execute('INSERT INTO models (name, type, path, vram_estimate, available) VALUES (?, ?, ?, ?, ?)',
(name, model_type, path, vram_estimate, 1 if available else 0))
conn.commit()
else:
# Update availability if it's not already available
if available:
cursor.execute('UPDATE models SET available = 1 WHERE path = ?', (path,))
conn.commit()
conn.close()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment