- setJobConfig(value, `config.process[0].datasets[${i}].folder_path`)}
+ options={datasetOptions}
+ />
+ {/* setJobConfig(value, `config.process[0].datasets[${i}].folder_path`)}
placeholder="eg. /path/to/images/folder"
required
- />
- */}
+ {/*
+ /> */}
([]);
+ const [status, setStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle');
+
+ const refreshDatasets = () => {
+ setStatus('loading');
+ fetch('/api/datasets/list')
+ .then(res => res.json())
+ .then(data => {
+ console.log('Datasets:', data);
+ // sort
+ data.sort((a: string, b: string) => a.localeCompare(b));
+ setDatasets(data);
+ setStatus('success');
+ })
+ .catch(error => {
+ console.error('Error fetching datasets:', error);
+ setStatus('error');
+ });
+ };
+ useEffect(() => {
+ refreshDatasets();
+ }, []);
+
+ return { datasets, setDatasets, status, refreshDatasets };
+}
diff --git a/ui/src/hooks/useGPUInfo.tsx b/ui/src/hooks/useGPUInfo.tsx
new file mode 100644
index 00000000..dd7e32fe
--- /dev/null
+++ b/ui/src/hooks/useGPUInfo.tsx
@@ -0,0 +1,32 @@
+'use client';
+
+import { GPUApiResponse } from '@/types';
+import { useEffect, useState } from 'react';
+
+export default function useGPUInfo() {
+ const [gpuList, setGpuList] = useState([]);
+ const [isGPUInfoLoaded, setIsLoaded] = useState(false);
+ useEffect(() => {
+ const fetchGpuInfo = async () => {
+ try {
+ const response = await fetch('/api/gpu');
+
+ if (!response.ok) {
+ throw new Error(`HTTP error! Status: ${response.status}`);
+ }
+
+ const data: GPUApiResponse = await response.json();
+ setGpuList(data.gpus.map(gpu => gpu.index).sort());
+ } catch (err) {
+ console.log(`Failed to fetch GPU data: ${err instanceof Error ? err.message : String(err)}`);
+ } finally {
+ setIsLoaded(true);
+ }
+ };
+
+ // Fetch immediately on component mount
+ fetchGpuInfo();
+ }, []);
+
+ return { gpuList, setGpuList, isGPUInfoLoaded };
+}
diff --git a/ui/src/hooks/useSettings.tsx b/ui/src/hooks/useSettings.tsx
new file mode 100644
index 00000000..15b5175e
--- /dev/null
+++ b/ui/src/hooks/useSettings.tsx
@@ -0,0 +1,28 @@
+'use client';
+
+import { useEffect, useState } from 'react';
+
+export default function useSettings() {
+ const [settings, setSettings] = useState({
+ HF_TOKEN: '',
+ TRAINING_FOLDER: '',
+ DATASETS_FOLDER: '',
+ });
+ const [isSettingsLoaded, setIsLoaded] = useState(false);
+ useEffect(() => {
+ // Fetch current settings
+ fetch('/api/settings')
+ .then(res => res.json())
+ .then(data => {
+ setSettings({
+ HF_TOKEN: data.HF_TOKEN || '',
+ TRAINING_FOLDER: data.TRAINING_FOLDER || '',
+ DATASETS_FOLDER: data.DATASETS_FOLDER || '',
+ });
+ setIsLoaded(true);
+ })
+ .catch(error => console.error('Error fetching settings:', error));
+ }, []);
+
+ return { settings, setSettings, isSettingsLoaded };
+}