Refactor: 모델 관리 리팩토링

This commit is contained in:
정현조 2024-09-23 16:05:23 +09:00
parent 722a15be7b
commit 89c873a12c

View File

@ -1,12 +1,11 @@
import { Rabbit, Bird, Turtle, Settings, Share } from 'lucide-react'; import { Rabbit, Bird, Turtle, Share } from 'lucide-react';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from '@/components/ui/drawer';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import ModelLineChart from '@/components/ModelLineChart'; import ModelLineChart from '@/components/ModelLineChart';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { useState, useEffect } from 'react'; import { useState } from 'react';
import ModelBarChart from '@/components/ModelBarChart'; import ModelBarChart from '@/components/ModelBarChart';
export default function ModelManage() { export default function ModelManage() {
@ -27,17 +26,7 @@ export default function ModelManage() {
const [lossData] = useState<MetricData[]>(dummyLossData); const [lossData] = useState<MetricData[]>(dummyLossData);
const [training, setTraining] = useState(false); const [training, setTraining] = useState(false);
const [selectedModel, setSelectedModel] = useState<string | null>(null);
useEffect(() => {
if (training) {
const socket = new WebSocket('ws://localhost:8080/ws');
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received data:', data);
};
return () => socket.close();
}
}, [training]);
const handleTrainingToggle = () => { const handleTrainingToggle = () => {
setTraining((prev) => !prev); setTraining((prev) => !prev);
@ -48,24 +37,6 @@ export default function ModelManage() {
<div className="flex flex-col"> <div className="flex flex-col">
<header className="bg-background sticky top-0 z-10 flex h-[57px] items-center gap-1 border-b px-4"> <header className="bg-background sticky top-0 z-10 flex h-[57px] items-center gap-1 border-b px-4">
<h1 className="text-xl font-semibold"> </h1> <h1 className="text-xl font-semibold"> </h1>
<Drawer>
<DrawerTrigger asChild>
<Button
variant="ghost"
size="icon"
className="md:hidden"
>
<Settings className="size-4" />
<span className="sr-only"></span>
</Button>
</DrawerTrigger>
<DrawerContent className="max-h-[80vh]">
<DrawerHeader>
<DrawerTitle></DrawerTitle>
</DrawerHeader>
<SettingsForm />
</DrawerContent>
</Drawer>
<Button <Button
variant="outline" variant="outline"
size="sm" size="sm"
@ -86,26 +57,44 @@ export default function ModelManage() {
<TabsTrigger value="results"> </TabsTrigger> <TabsTrigger value="results"> </TabsTrigger>
</TabsList> </TabsList>
{/* 모델 학습 탭 */}
<TabsContent value="train"> <TabsContent value="train">
<div className="grid gap-8 md:grid-cols-2"> <div className="grid gap-8 md:grid-cols-2">
<div className="flex flex-col gap-6"> <div className="flex flex-col gap-6">
<SettingsForm /> <SettingsForm />
<Button <Button
variant={training ? 'destructive' : 'default'} variant={training ? 'destructive' : 'outlinePrimary'}
size="lg" size="lg"
onClick={handleTrainingToggle} onClick={handleTrainingToggle}
> >
{training ? '학습 중단' : '학습 시작'} {training ? '학습 중단' : '학습 시작'}
</Button> </Button>
</div> </div>
<div className="flex flex-col justify-center"> <div className="flex flex-col justify-center">
<ModelLineChart data={lossData} /> <ModelLineChart data={lossData} />
</div> </div>
</div> </div>
</TabsContent> </TabsContent>
{/* 모델 평가 탭 */}
<TabsContent value="results"> <TabsContent value="results">
{/* 모델 선택 */}
<div className="mb-4">
<Label htmlFor="select-model"> </Label>
<Select onValueChange={setSelectedModel}>
<SelectTrigger id="select-model">
<SelectValue placeholder="모델을 선택하세요" />
</SelectTrigger>
<SelectContent>
<SelectItem value="genesis">Genesis</SelectItem>
<SelectItem value="explorer">Explorer</SelectItem>
<SelectItem value="quantum">Quantum</SelectItem>
</SelectContent>
</Select>
</div>
{/* 선택된 모델에 따른 BarChart 및 Labeling Preview */}
{selectedModel && (
<div className="grid gap-8 md:grid-cols-2"> <div className="grid gap-8 md:grid-cols-2">
<div className="flex flex-col gap-6"> <div className="flex flex-col gap-6">
<ModelBarChart <ModelBarChart
@ -122,6 +111,7 @@ export default function ModelManage() {
<LabelingPreview /> <LabelingPreview />
</div> </div>
</div> </div>
)}
</TabsContent> </TabsContent>
</Tabs> </Tabs>
</main> </main>
@ -190,11 +180,22 @@ function SettingsForm() {
placeholder="-1" placeholder="-1"
id="batch" id="batch"
/> />
<SelectWithLabel
label="옵티마이저"
id="optimizer"
options={['SGD', 'Adam', 'AdamW', 'NAdam', 'RAdam', 'RMSProp']}
placeholder="옵티마이저 선택"
/>
<InputWithLabel <InputWithLabel
label="학습률(LR0)" label="학습률(LR0)"
placeholder="0.01" placeholder="0.01"
id="lr0" id="lr0"
/> />
<InputWithLabel
label="학습률(LRF)"
placeholder="0.01"
id="lrf"
/>
</div> </div>
</fieldset> </fieldset>
</form> </form>
@ -244,3 +245,32 @@ function InputWithLabel({ label, id, placeholder }: InputWithLabelProps) {
</div> </div>
); );
} }
interface SelectWithLabelProps {
label: string;
id: string;
options: string[];
placeholder: string;
}
function SelectWithLabel({ label, id, options, placeholder }: SelectWithLabelProps) {
return (
<div className="grid gap-3">
<Label htmlFor={id}>{label}</Label>
<Select>
<SelectTrigger id={id}>
<SelectValue placeholder={placeholder} />
</SelectTrigger>
<SelectContent>
{options.map((option) => (
<SelectItem
key={option}
value={option}
>
{option}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
);
}