diff --git a/ui/cron/actions/startJob.ts b/ui/cron/actions/startJob.ts index 8f0eb8bd65..de761b228e 100644 --- a/ui/cron/actions/startJob.ts +++ b/ui/cron/actions/startJob.ts @@ -3,7 +3,7 @@ import { Job } from '@prisma/client'; import { spawn } from 'child_process'; import path from 'path'; import fs from 'fs'; -import { TOOLKIT_ROOT, getTrainingFolder, getHFToken } from '../paths'; +import { TOOLKIT_ROOT, getTrainingFolder, getHFToken, getOfflineMode } from '../paths'; import { resolvePythonPath } from '../pythonPath'; const isWindows = process.platform === 'win32'; @@ -81,6 +81,10 @@ const startAndWatchJob = (job: Job) => { additionalEnv.HF_TOKEN = hfToken; } + if (await getOfflineMode()) { + additionalEnv.HF_HUB_OFFLINE = '1'; + } + // Add the --log argument to the command const args = [runFilePath, configPath, '--log', logPath]; diff --git a/ui/cron/paths.ts b/ui/cron/paths.ts index ef28b97359..4cac08ee0d 100644 --- a/ui/cron/paths.ts +++ b/ui/cron/paths.ts @@ -35,3 +35,12 @@ export const getHFToken = async () => { } return token; }; + +export const getOfflineMode = async () => { + const row = await prisma.settings.findFirst({ + where: { + key: 'OFFLINE_MODE', + }, + }); + return row?.value === '1'; +}; diff --git a/ui/src/app/api/settings/route.ts b/ui/src/app/api/settings/route.ts index 62528cdd0b..5f808baf5f 100644 --- a/ui/src/app/api/settings/route.ts +++ b/ui/src/app/api/settings/route.ts @@ -20,6 +20,7 @@ export async function GET() { if (!settingsObject.DATASETS_FOLDER || settingsObject.DATASETS_FOLDER === '') { settingsObject.DATASETS_FOLDER = defaultDatasetsFolder; } + settingsObject.OFFLINE_MODE = settingsObject.OFFLINE_MODE === '1'; return NextResponse.json(settingsObject); } catch (error) { return NextResponse.json({ error: 'Failed to fetch settings' }, { status: 500 }); @@ -29,15 +30,21 @@ export async function GET() { export async function POST(request: Request) { try { const body = await request.json(); - const { HF_TOKEN, TRAINING_FOLDER, DATASETS_FOLDER } = body; + const { HF_TOKEN, OFFLINE_MODE, TRAINING_FOLDER, DATASETS_FOLDER } = body; + const offlineModeValue = OFFLINE_MODE ? '1' : '0'; - // Upsert both settings + // Persist all settings in the key/value store await Promise.all([ prisma.settings.upsert({ where: { key: 'HF_TOKEN' }, update: { value: HF_TOKEN }, create: { key: 'HF_TOKEN', value: HF_TOKEN }, }), + prisma.settings.upsert({ + where: { key: 'OFFLINE_MODE' }, + update: { value: offlineModeValue }, + create: { key: 'OFFLINE_MODE', value: offlineModeValue }, + }), prisma.settings.upsert({ where: { key: 'TRAINING_FOLDER' }, update: { value: TRAINING_FOLDER }, diff --git a/ui/src/app/settings/page.tsx b/ui/src/app/settings/page.tsx index 8b0d880160..9897973f5c 100644 --- a/ui/src/app/settings/page.tsx +++ b/ui/src/app/settings/page.tsx @@ -68,6 +68,23 @@ export default function Settings() { /> +