Spaces:
Running
Running
| import{j as e,A as we,m as U}from"./vendor-Dy_Aqit6.js";import{a as k,b as De}from"./plotly-BRtgkqNO.js";import{c as V,N as Pe,O as Ae,u as Y,a as W,D as K,i as R,v as ke,A as ee,T as Ce,Z as pe,d as ne,z as be,j as Oe,o as ge,y as se,J as ce,E as $e,P as Q,X as _e,s as Ie,C as Le,r as Re,x as Ee,G as Fe,S as ze}from"./index-gw3efmjR.js";import{U as te}from"./upload-Dy2l51-u.js";import{L as oe}from"./loader-2-BImNpDl0.js";import{I as J,F as Ue}from"./image-Tdd659JJ.js";import{C as z}from"./check-circle-2-DFZSh8uk.js";import{F as Ve}from"./filter-CYakqm8f.js";import{L as Ye}from"./list-4zf6XrJQ.js";import{T as ae}from"./target-9BTPNsCE.js";import{P as Me}from"./play-DaRbgWxb.js";import{S as Be}from"./square-5qwWf1xI.js";import{P as He,X as Se,Y as me,R as Je,a0 as Ge,a3 as We,a1 as Ze,a2 as Ke}from"./generateCategoricalChart-CgN9tTma.js";import{L as xe}from"./Line-DyDjKcer.js";import{B as re}from"./bar-chart-3-DmJ5EovG.js";import{H as qe}from"./hard-drive-BTxiPIf1.js";import{D as le}from"./download-BlP0QUf_.js";import{T as fe}from"./trending-up-CvRTvx2k.js";import{S as Xe}from"./save-B-Sh_lI1.js";import{B as X}from"./box-Bgt8EZdi.js";import{C as Qe}from"./copy-BRbVh0Bh.js";import{C as es}from"./clock-5YOVlxXU.js";import{B as ve}from"./bar-chart-2-Lx_0ZOo0.js";import{L as ss}from"./layers-C98tUB4O.js";import{R as ts}from"./rocket-WQ9kUmAB.js";import{N as ye}from"./network-4_56SZGh.js";import"./clsx-B-dksMZM.js";import"./debounce-Bnr1Yz2W.js";/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const de=V("Crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const as=V("Crown",[["path",{d:"m2 4 3 12h14l3-12-6 7-4-7-4 7-6-7zm3 16h14",key:"zkxr6b"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const rs=V("FileCode",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m10 13-2 2 2 2",key:"17smn8"}],["path",{d:"m14 17 2-2-2-2",key:"14mezr"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const ls=V("FlaskConical",[["path",{d:"M10 2v7.527a2 2 0 0 1-.211.896L4.72 20.55a1 1 0 0 0 .9 1.45h12.76a1 1 0 0 0 .9-1.45l-5.069-10.127A2 2 0 0 1 14 9.527V2",key:"pzvekw"}],["path",{d:"M8.5 2h7",key:"csnxdl"}],["path",{d:"M7 16h10",key:"wp8him"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const os=V("LayoutGrid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Te=V("PanelsTopLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const je=V("Pause",[["rect",{width:"4",height:"16",x:"6",y:"4",key:"iffhe4"}],["rect",{width:"4",height:"16",x:"14",y:"4",key:"sjin7j"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const Ne=V("SlidersHorizontal",[["line",{x1:"21",x2:"14",y1:"4",y2:"4",key:"obuewd"}],["line",{x1:"10",x2:"3",y1:"4",y2:"4",key:"1q6298"}],["line",{x1:"21",x2:"12",y1:"12",y2:"12",key:"1iu8h1"}],["line",{x1:"8",x2:"3",y1:"12",y2:"12",key:"ntss68"}],["line",{x1:"21",x2:"16",y1:"20",y2:"20",key:"14d8ph"}],["line",{x1:"12",x2:"3",y1:"20",y2:"20",key:"m0wm8r"}],["line",{x1:"14",x2:"14",y1:"2",y2:"6",key:"14e1ph"}],["line",{x1:"8",x2:"8",y1:"10",y2:"14",key:"1i6ji0"}],["line",{x1:"16",x2:"16",y1:"18",y2:"22",key:"1lctlv"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const is=V("Smartphone",[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const ds=V("Star",[["polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2",key:"8f66p6"}]]);/** | |
| * @license lucide-react v0.344.0 - ISC | |
| * | |
| * This source code is licensed under the ISC license. | |
| * See the LICENSE file in the root directory of this source tree. | |
| */const he=V("Trophy",[["path",{d:"M6 9H4.5a2.5 2.5 0 0 1 0-5H6",key:"17hqa7"}],["path",{d:"M18 9h1.5a2.5 2.5 0 0 0 0-5H18",key:"lmptdp"}],["path",{d:"M4 22h16",key:"57wxv0"}],["path",{d:"M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22",key:"1nw9bq"}],["path",{d:"M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22",key:"1np0yb"}],["path",{d:"M18 2H6v7a6 6 0 0 0 12 0V2Z",key:"u46fv3"}]]);var ns=He({chartName:"LineChart",GraphicalChild:xe,axisComponents:[{axisType:"xAxis",AxisComp:Se},{axisType:"yAxis",AxisComp:me}],formatAxisMap:Je});const G=Pe()(Ae(t=>({activeProject:null,datasets:[],activeDatasetId:null,trainingJobs:[],activeJobId:null,experiments:[],models:[],predictions:[],activeTab:"overview",trainingMode:"fast",cvCache:{},setActiveProject:r=>t({activeProject:r}),setDatasets:r=>t({datasets:r}),addDataset:r=>t(h=>({datasets:[r,...h.datasets],activeDatasetId:r.id})),deleteDataset:async r=>{try{(await fetch(`/api/v1/cv/datasets/${r}`,{method:"DELETE"})).ok&&t(u=>({datasets:u.datasets.filter(p=>p.id!==r),activeDatasetId:u.activeDatasetId===r?null:u.activeDatasetId}))}catch(h){console.error("Failed to delete dataset:",h)}},setActiveDatasetId:r=>t({activeDatasetId:r}),setTrainingJobs:r=>t({trainingJobs:r}),addTrainingJob:r=>t(h=>({trainingJobs:[...h.trainingJobs,r]})),updateTrainingJob:(r,h)=>t(u=>({trainingJobs:u.trainingJobs.map(p=>p.id===r?{...p,...h}:p)})),setActiveJobId:r=>t({activeJobId:r}),setExperiments:r=>t({experiments:r}),setModels:r=>t({models:r}),setPredictions:r=>t({predictions:r}),setActiveTab:r=>t({activeTab:r}),setTrainingMode:r=>t({trainingMode:r}),setCvCache:(r,h)=>t(u=>({cvCache:{...u.cvCache,[r]:h}})),clearCvCache:r=>t(h=>{if(r){const u={...h.cvCache};return delete u[r],{cvCache:u}}return{cvCache:{}}})}),{name:"datavision-cv-store",partialize:t=>({activeProject:t.activeProject,activeTab:t.activeTab,trainingMode:t.trainingMode,cvCache:t.cvCache,activeDatasetId:t.activeDatasetId,activeJobId:t.activeJobId})})),cs=({onUploadComplete:t})=>{const{isDark:r}=Y(),h=W(),u=k.useRef(null),[p,C]=k.useState(!1),[T,x]=k.useState(!1),[M,o]=k.useState(0),i=d=>{d.preventDefault(),C(!0)},g=()=>{C(!1)},w=d=>{d.preventDefault(),C(!1),d.dataTransfer.files&&d.dataTransfer.files.length>0&&j(d.dataTransfer.files[0])},c=d=>{d.target.files&&d.target.files.length>0&&j(d.target.files[0])},j=async d=>{var v,s;if(![".zip",".tar",".tar.gz",".tgz"].some(m=>d.name.toLowerCase().endsWith(m))){h.error("Please upload your dataset as a compressed folder (.zip, .tar, .tar.gz, .tgz) so we can preserve your directory structure.");return}if(d.size>20*1024*1024*1024){h.error("Vision datasets can be up to 20 GB. Please choose a smaller archive.");return}x(!0),o(0);const l=new FormData;l.append("file",d);try{const m=setInterval(()=>{o(N=>Math.min(N+10,90))},500),b=await R.post("/api/v1/cv/datasets",l,{headers:{"Content-Type":"multipart/form-data"}});clearInterval(m),o(100),setTimeout(()=>{x(!1);const N=b.data.dataset||(b.data.id?b.data:null);N?(h.success("Dataset uploaded and analyzed successfully!"),t(N)):h.error(b.data.error||"Failed to process dataset.")},500)}catch(m){x(!1),h.error(((s=(v=m.response)==null?void 0:v.data)==null?void 0:s.detail)||"Upload failed")}};return e.jsxs("div",{className:"space-y-8 max-w-5xl mx-auto",children:[e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",style:{color:"var(--text-primary)"},children:"Upload Vision Dataset"}),e.jsx("p",{className:"text-sm",style:{color:"var(--text-muted)"},children:"Drop a compressed archive of your images and annotations. We'll automatically detect the format."})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsx("div",{className:"lg:col-span-2 space-y-6",children:e.jsxs("div",{className:`relative overflow-hidden border-2 border-dashed rounded-3xl p-12 text-center transition-all duration-300 ${p?"border-emerald-500 bg-emerald-500/10 scale-[1.02]":r?"border-white/20 hover:border-emerald-500/50 hover:bg-white/5":"border-slate-300 hover:border-emerald-500/50 hover:bg-slate-50"}`,onDragOver:i,onDragLeave:g,onDrop:w,onClick:()=>{var d;return!T&&((d=u.current)==null?void 0:d.click())},style:{cursor:T?"wait":"pointer",minHeight:"320px"},children:[p&&e.jsx("div",{className:"absolute inset-0 bg-emerald-500/20 backdrop-blur-sm z-10 flex items-center justify-center",children:e.jsx(te,{className:"w-16 h-16 text-emerald-500 animate-bounce"})}),e.jsx("input",{type:"file",ref:u,onChange:c,className:"hidden",accept:".zip,.tar,.tar.gz,.tgz"}),e.jsx(we,{mode:"wait",children:T?e.jsxs(U.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0},className:"flex flex-col items-center justify-center space-y-6 h-full",children:[e.jsxs("div",{className:"relative",children:[e.jsx(oe,{className:"w-16 h-16 text-emerald-500 animate-spin"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("span",{className:"text-xs font-bold text-emerald-500",children:[M,"%"]})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold mb-2",style:{color:"var(--text-primary)"},children:"Processing Dataset..."}),e.jsx("p",{className:"text-sm max-w-xs mx-auto",style:{color:"var(--text-muted)"},children:"Extracting images, analyzing structure, and calculating health score."})]}),e.jsx("div",{className:"w-full max-w-sm bg-black/10 dark:bg-white/10 rounded-full h-2 overflow-hidden",children:e.jsx(U.div,{className:"bg-emerald-500 h-full",initial:{width:0},animate:{width:`${M}%`},transition:{ease:"linear",duration:.5}})})]},"uploading"):e.jsxs(U.div,{initial:{opacity:0},animate:{opacity:1},className:"flex flex-col items-center justify-center h-full gap-6",children:[e.jsx("div",{className:`p-5 rounded-full shadow-lg ${r?"bg-emerald-500/20 text-emerald-400 shadow-emerald-500/20":"bg-emerald-50 text-emerald-600 shadow-emerald-500/20"}`,children:e.jsx(te,{className:"w-10 h-10"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-bold mb-2",style:{color:"var(--text-primary)"},children:"Click or drag archive here"}),e.jsx("p",{className:"text-sm px-4 max-w-md mx-auto",style:{color:"var(--text-muted)"},children:"Supports .zip, .tar, .tar.gz, and .tgz formats up to 20 GB."})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-3 mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium px-4 py-2 rounded-xl transition-colors hover:bg-emerald-500/10 hover:text-emerald-500",style:{backgroundColor:"var(--bg-secondary)",color:"var(--text-muted)"},children:[e.jsx(J,{className:"w-4 h-4"})," Classification"]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium px-4 py-2 rounded-xl transition-colors hover:bg-emerald-500/10 hover:text-emerald-500",style:{backgroundColor:"var(--bg-secondary)",color:"var(--text-muted)"},children:[e.jsx(Ue,{className:"w-4 h-4"})," YOLOv8"]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium px-4 py-2 rounded-xl transition-colors hover:bg-emerald-500/10 hover:text-emerald-500",style:{backgroundColor:"var(--bg-secondary)",color:"var(--text-muted)"},children:[e.jsx(K,{className:"w-4 h-4"})," COCO"]})]})]},"idle")})]})}),e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"p-6 rounded-3xl border bg-gradient-to-b from-transparent to-black/5 dark:to-white/5",style:{borderColor:"var(--border-color)"},children:[e.jsxs("h4",{className:"font-bold flex items-center gap-2 mb-4",style:{color:"var(--text-primary)"},children:[e.jsx(z,{className:"w-5 h-5 text-emerald-500"})," Auto-Detection"]}),e.jsx("p",{className:"text-sm leading-relaxed mb-6",style:{color:"var(--text-muted)"},children:"Datavision will automatically scan your folder structure and annotations to figure out the task type (Detection, Classification, Segmentation)."}),e.jsx("h4",{className:"font-bold text-sm mb-3",style:{color:"var(--text-primary)"},children:"Expected YOLO Structure:"}),e.jsxs("div",{className:"p-4 rounded-xl font-mono text-xs space-y-2 border",style:{backgroundColor:"var(--bg-secondary)",color:"var(--text-muted)",borderColor:"var(--border-color)"},children:[e.jsx("div",{className:"text-emerald-500 font-bold",children:"dataset.zip"}),e.jsxs("div",{className:"pl-4 border-l border-white/10",children:[e.jsx("div",{children:"├── images/"}),e.jsxs("div",{className:"pl-4 border-l border-white/10 text-slate-500",children:[e.jsx("div",{children:"├── train/ (img1.jpg...)"}),e.jsx("div",{children:"└── val/"})]}),e.jsx("div",{children:"├── labels/"}),e.jsxs("div",{className:"pl-4 border-l border-white/10 text-slate-500",children:[e.jsx("div",{children:"├── train/ (img1.txt...)"}),e.jsx("div",{children:"└── val/"})]}),e.jsx("div",{children:"└── data.yaml"})]})]})]})})]})]})},ms=()=>{const{isDark:t}=Y(),{activeDatasetId:r,datasets:h,setActiveDatasetId:u,deleteDataset:p}=G(),[C,T]=k.useState(""),[x,M]=k.useState("grid"),[o,i]=k.useState(!1),[g,w]=k.useState(12),c=h.find(j=>j.id===r);return c?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(ke,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4",style:{color:"var(--text-muted)"}}),e.jsx("input",{type:"text",placeholder:"Search images or classes...",value:C,onChange:j=>T(j.target.value),className:"w-full pl-10 pr-4 py-2 rounded-xl border focus:ring-2 focus:ring-emerald-500/50 outline-none transition-all",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)",color:"var(--text-primary)"}})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{className:"p-2 rounded-xl border hover:bg-black/5 dark:hover:bg-white/5 transition-colors",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"},children:e.jsx(Ve,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex bg-black/5 dark:bg-white/5 rounded-xl p-1 border",style:{borderColor:"var(--border-color)"},children:[e.jsx("button",{onClick:()=>M("grid"),className:`p-1.5 rounded-lg transition-colors ${x==="grid"?"bg-white dark:bg-slate-800 shadow-sm":"hover:bg-black/5 dark:hover:bg-white/5"}`,style:{color:x==="grid"?"var(--text-primary)":"var(--text-muted)"},children:e.jsx(os,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>M("list"),className:`p-1.5 rounded-lg transition-colors ${x==="list"?"bg-white dark:bg-slate-800 shadow-sm":"hover:bg-black/5 dark:hover:bg-white/5"}`,style:{color:x==="list"?"var(--text-primary)":"var(--text-muted)"},children:e.jsx(Ye,{className:"w-4 h-4"})})]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4 p-4 rounded-xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-muted)"},children:"Dataset:"}),e.jsx("span",{className:"text-sm font-bold px-2 py-1 rounded-md",style:{backgroundColor:"var(--bg-secondary)",color:"var(--text-primary)"},children:c.name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-muted)"},children:"Images:"}),e.jsx("span",{className:"text-sm font-bold",style:{color:"var(--text-primary)"},children:c.numImages})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-muted)"},children:"Classes:"}),e.jsx("span",{className:"text-sm font-bold",style:{color:"var(--text-primary)"},children:c.numClasses})]}),(()=>{var d;const j=typeof c.healthScore=="object"?((d=c.healthScore)==null?void 0:d.score)??100:c.healthScore??100;return e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-muted)"},children:"Health:"}),e.jsxs("div",{className:"flex items-center gap-1",children:[j>80?e.jsx(z,{className:"w-4 h-4 text-emerald-500"}):j>50?e.jsx(ee,{className:"w-4 h-4 text-amber-500"}):e.jsx(ee,{className:"w-4 h-4 text-red-500"}),e.jsxs("span",{className:`text-sm font-bold ${j>80?"text-emerald-500":j>50?"text-amber-500":"text-red-500"}`,children:[j,"%"]})]})]})})(),e.jsx("div",{className:"ml-auto flex items-center",children:e.jsxs("button",{onClick:async()=>{window.confirm(`Are you sure you want to permanently delete "${c.name}"? This action cannot be undone.`)&&(i(!0),await p(c.id),i(!1))},disabled:o,className:`px-4 py-2 rounded-xl border border-red-500/20 bg-red-500/10 transition-colors flex items-center gap-2 ${o?"opacity-50 cursor-not-allowed":"hover:bg-red-500 hover:text-white text-red-500"}`,title:"Delete Dataset",children:[e.jsx(Ce,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-bold",children:"Delete Dataset"})]})})]}),e.jsx("div",{className:`grid gap-4 ${x==="grid"?"grid-cols-2 md:grid-cols-3 xl:grid-cols-4":"grid-cols-1"}`,children:Array.from({length:Math.min(g,c.numImages)}).map((j,d)=>e.jsxs("div",{className:"group relative rounded-xl overflow-hidden border aspect-square flex items-center justify-center bg-slate-100 dark:bg-slate-800 transition-all hover:border-emerald-500/50",style:{borderColor:"var(--border-color)"},children:[e.jsx("img",{src:`/api/v1/cv/datasets/${c.id}/images/${d}`,alt:`Dataset Image ${d}`,className:"w-full h-full object-cover",onError:S=>{var l,v,s,m;S.currentTarget.style.display="none",(v=(l=S.currentTarget.parentElement)==null?void 0:l.querySelector(".fallback-icon"))==null||v.classList.remove("hidden"),(m=(s=S.currentTarget.parentElement)==null?void 0:s.querySelector(".fallback-icon"))==null||m.classList.add("flex")}}),e.jsx("div",{className:"fallback-icon hidden absolute inset-0 items-center justify-center bg-black/5 dark:bg-white/5",children:e.jsx(J,{className:"w-10 h-10 text-emerald-500/20"})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx("div",{className:"absolute bottom-3 left-3 right-3 flex justify-between items-end",children:e.jsxs("div",{children:[e.jsxs("span",{className:"text-xs font-medium text-white/70",children:["Sample_",d+1]}),e.jsx("p",{className:"text-sm font-bold text-white truncate",children:c.classes[d%Math.max(1,c.classes.length)]||"Unknown"})]})})})]},d))}),c.numImages>g&&e.jsx("div",{className:"text-center pt-4",children:e.jsxs("button",{onClick:()=>w(j=>j+12),className:"px-5 py-2.5 rounded-xl border text-sm font-semibold hover:bg-emerald-500/10 hover:border-emerald-500/30 hover:text-emerald-500 transition-all flex items-center gap-2 mx-auto",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"},children:["Load More Images (",c.numImages-g," remaining)"]})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(J,{className:"w-16 h-16 mb-4 text-slate-300 dark:text-slate-700"}),e.jsx("h3",{className:"text-xl font-bold",style:{color:"var(--text-primary)"},children:"No Dataset Selected"}),e.jsx("p",{className:"mt-2 text-sm max-w-md",style:{color:"var(--text-muted)"},children:"Please select a dataset from the overview or upload a new one to view its gallery."})]})},xs=({onStartTraining:t,disabled:r,selectedTaskType:h})=>{var b,N,_,I;const{isDark:u}=Y(),{trainingMode:p,setTrainingMode:C,activeDatasetId:T,datasets:x}=G(),M=x.find(y=>y.id===T),o=h||(M==null?void 0:M.taskType)||"object_detection",[i,g]=k.useState({model:o==="classification"?"resnet50":o==="pose_estimation"?"yolov8s-pose":o==="ocr"?"trocr":o==="instance_segmentation"||o==="semantic_segmentation"?"yolov8s-seg":"yolov8s",epochs:50,batchSize:16,learningRate:.001,imageSize:640,optimizer:"AdamW",weightDecay:5e-4,augmentations:["mosaic","mixup"]}),w=()=>{t(p,i,o)},c=[{id:"fast",label:"Fast Mode",icon:pe,desc:"Quick prototyping, 10-20 epochs, basic augmentations"},{id:"ultra",label:"Ultra Mode",icon:as,desc:"State-of-the-art accuracy, heavy augmentations, 100+ epochs"},{id:"expert",label:"Expert Mode",icon:ne,desc:"Full manual hyperparameter control"}],s=o==="classification"?[{category:"Transformers (SOTA)",models:[{id:"vit_b_16",name:"ViT Base 16",desc:"Vision Transformer",params:"86M"},{id:"vit_l_16",name:"ViT Large 16",desc:"Heavy Transformer",params:"304M"},{id:"swin_t",name:"Swin-T",desc:"Hierarchical ViT",params:"28M"},{id:"deit_base",name:"DeiT Base",desc:"Data-efficient ViT",params:"86M"}]},{category:"EfficientNet (Balanced)",models:[{id:"efficientnet_b0",name:"EfficientNet-B0",desc:"Fast baseline",params:"5M"},{id:"efficientnet_b4",name:"EfficientNet-B4",desc:"High accuracy",params:"19M"},{id:"efficientnet_v2_s",name:"EfficientNetV2-S",desc:"Faster training",params:"21M"},{id:"convnext_tiny",name:"ConvNeXt Tiny",desc:"Modern ConvNet",params:"28M"}]},{category:"Classic ResNet",models:[{id:"resnet18",name:"ResNet-18",desc:"Lightweight classic",params:"11M"},{id:"resnet50",name:"ResNet-50",desc:"Industry standard",params:"25M"},{id:"resnet101",name:"ResNet-101",desc:"Deeper network",params:"44M"}]},{category:"Mobile & Edge",models:[{id:"mobilenet_v3_small",name:"MobileNetV3 S",desc:"Ultra-light",params:"2.5M"},{id:"mobilenet_v3_large",name:"MobileNetV3 L",desc:"Mobile standard",params:"5.4M"},{id:"shufflenet_v2_x1_0",name:"ShuffleNet V2",desc:"Efficient edge",params:"2.3M"}]}]:o==="pose_estimation"?[{category:"YOLO Pose Estimation",models:[{id:"yolo11n-pose",name:"YOLO11n-Pose",desc:"Fast pose tracking",params:"2.9M"},{id:"yolov8s-pose",name:"YOLOv8s-Pose",desc:"Standard keypoints",params:"11.6M"},{id:"yolov8x-pose",name:"YOLOv8x-Pose",desc:"SOTA pose accuracy",params:"69.4M"}]},{category:"Classic Keypoints",models:[{id:"hrnet_w32",name:"HRNet-W32",desc:"High-resolution keypoints",params:"28.5M"},{id:"openpose",name:"OpenPose Multi-Person",desc:"Real-time multi-person",params:"26M"}]}]:o==="ocr"?[{category:"Text Recognition & Detection",models:[{id:"trocr",name:"TrOCR (Transformer OCR)",desc:"Encoder-decoder text OCR",params:"62M"},{id:"paddle_ocr",name:"PaddleOCR Engine",desc:"Multilingual document OCR",params:"15M"},{id:"easy_ocr",name:"EasyOCR Text Pipeline",desc:"Fast multi-language text",params:"12M"}]}]:o==="instance_segmentation"||o==="semantic_segmentation"?[{category:"Foundation Models",models:[{id:"sam_b",name:"SAM Base",desc:"Segment Anything",params:"91M"},{id:"sam2_t",name:"SAM 2 Tiny",desc:"Video/Image SOTA",params:"38M"}]},{category:"YOLO Segmentation",models:[{id:"yolo11n-seg",name:"YOLO11n-Seg",desc:"Fast instance seg",params:"2.8M"},{id:"yolov8s-seg",name:"YOLOv8s-Seg",desc:"Standard instance",params:"11.8M"}]},{category:"Classic",models:[{id:"mask_rcnn",name:"Mask R-CNN",desc:"Standard two-stage",params:"44M"},{id:"deeplabv3",name:"DeepLabV3",desc:"Semantic seg",params:"39M"}]}]:[{category:"YOLOv11 (State of the Art)",models:[{id:"yolo11n",name:"YOLO11 Nano",desc:"Ultra-fast edge deployment",params:"2.6M"},{id:"yolo11s",name:"YOLO11 Small",desc:"Balanced speed/accuracy",params:"9.4M"},{id:"yolo11m",name:"YOLO11 Medium",desc:"Standard use cases",params:"20.1M"},{id:"yolo11l",name:"YOLO11 Large",desc:"High accuracy",params:"25.3M"},{id:"yolo11x",name:"YOLO11 Extra",desc:"Max performance",params:"56.9M"}]},{category:"YOLOv10 / v9",models:[{id:"yolov10n",name:"YOLOv10 Nano",desc:"NMS-free end-to-end",params:"2.7M"},{id:"yolov10x",name:"YOLOv10 Extra",desc:"Max NMS-free perf",params:"31.6M"},{id:"yolov9c",name:"YOLOv9 Compact",desc:"PGI architecture",params:"25.3M"},{id:"yolov9e",name:"YOLOv9 Extended",desc:"GELAN heavy",params:"58.1M"}]},{category:"YOLOv8 (Industry Standard)",models:[{id:"yolov8n",name:"YOLOv8 Nano",desc:"Extremely fast",params:"3.2M"},{id:"yolov8s",name:"YOLOv8 Small",desc:"Good baseline",params:"11.2M"},{id:"yolov8x",name:"YOLOv8 Extra",desc:"Heavy but precise",params:"68.2M"}]},{category:"Transformers & Other",models:[{id:"rtdetr-l",name:"RT-DETR Large",desc:"Real-time Transformer",params:"32M"},{id:"rtdetr-x",name:"RT-DETR Extra",desc:"SOTA Transformer",params:"67M"},{id:"faster_rcnn",name:"Faster R-CNN",desc:"Classic two-stage",params:"41M"},{id:"ssd_mobilenet",name:"SSD MobileNet",desc:"Lightweight mobile",params:"4M"},{id:"retinanet",name:"RetinaNet",desc:"Focal loss pioneer",params:"38M"},{id:"efficientdet_d0",name:"EfficientDet-D0",desc:"BiFPN architecture",params:"4M"}]}],m=y=>e.jsx("div",{className:"space-y-6",children:y.map((D,L)=>e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3 px-1",style:{color:"var(--text-muted)"},children:D.category}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3",children:D.models.map(O=>e.jsxs("div",{onClick:()=>g({...i,model:O.id}),className:`relative p-4 rounded-xl border cursor-pointer transition-all ${i.model===O.id?"border-emerald-500 bg-emerald-500/10 shadow-[0_0_15px_rgba(16,185,129,0.1)]":"hover:border-emerald-500/50 hover:bg-black/5 dark:hover:bg-white/5"}`,style:{borderColor:i.model===O.id?"":"var(--border-color)"},children:[i.model===O.id&&e.jsx("div",{className:"absolute top-2 right-2 text-emerald-500",children:e.jsx(Oe,{className:"w-4 h-4"})}),e.jsx("div",{className:"font-bold mb-1",style:{color:"var(--text-primary)"},children:O.name}),e.jsx("div",{className:"text-xs mb-2",style:{color:"var(--text-muted)"},children:O.desc}),e.jsxs("div",{className:"text-[10px] font-mono px-2 py-1 bg-black/10 dark:bg-white/10 rounded w-fit text-slate-500",children:[O.params," Params"]})]},O.id))})]},L))});return e.jsxs("div",{className:"space-y-8",children:[e.jsx("div",{className:"flex p-1 rounded-xl bg-black/5 dark:bg-white/5 border w-fit",style:{borderColor:"var(--border-color)"},children:c.map(y=>e.jsxs("button",{onClick:()=>C(y.id),className:`flex items-center gap-2 px-6 py-2.5 rounded-lg text-sm font-medium transition-all ${p===y.id?"bg-white dark:bg-slate-800 shadow-sm text-emerald-500":"hover:bg-black/5 dark:hover:bg-white/5"}`,style:{color:p===y.id?"":"var(--text-muted)"},children:[e.jsx(y.icon,{className:"w-4 h-4"}),y.label]},y.id))}),e.jsxs("div",{className:"p-4 rounded-xl border bg-emerald-500/5",style:{borderColor:"var(--border-color)"},children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--text-primary)"},children:(b=c.find(y=>y.id===p))==null?void 0:b.desc}),p==="fast"&&e.jsxs("p",{className:"text-xs mt-2",style:{color:"var(--text-muted)"},children:["Note: Fast Mode will automatically select a lightweight model (",o==="classification"?"ResNet-18":"YOLO11n",") and train for 20 epochs. Model architecture selection is disabled in Fast Mode."]})]}),p!=="fast"&&e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"space-y-4 p-5 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6 border-b pb-4",style:{borderColor:"var(--border-color)"},children:[e.jsx(be,{className:"w-6 h-6 text-emerald-500"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-lg",style:{color:"var(--text-primary)"},children:"Model Architecture"}),e.jsx("p",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Select a foundation model to fine-tune on your dataset."})]})]}),m(s)]}),p==="expert"&&e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"space-y-4 p-5 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6 border-b pb-4",style:{borderColor:"var(--border-color)"},children:[e.jsx(ne,{className:"w-6 h-6 text-emerald-500"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-bold text-lg",style:{color:"var(--text-primary)"},children:"Advanced Hyperparameters"}),e.jsx("p",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Fine-tune the training process manually."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:"var(--text-muted)"},children:"Epochs"}),e.jsx("input",{type:"number",value:i.epochs,onChange:y=>g({...i,epochs:parseInt(y.target.value)}),className:"w-full p-2.5 rounded-xl border outline-none bg-transparent focus:border-emerald-500",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:"var(--text-muted)"},children:"Batch Size"}),e.jsx("input",{type:"number",value:i.batchSize,onChange:y=>g({...i,batchSize:parseInt(y.target.value)}),className:"w-full p-2.5 rounded-xl border outline-none bg-transparent focus:border-emerald-500",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:"var(--text-muted)"},children:"Learning Rate"}),e.jsx("input",{type:"number",step:"0.0001",value:i.learningRate,onChange:y=>g({...i,learningRate:parseFloat(y.target.value)}),className:"w-full p-2.5 rounded-xl border outline-none bg-transparent focus:border-emerald-500",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:"var(--text-muted)"},children:"Image Size"}),e.jsx("input",{type:"number",value:i.imageSize,onChange:y=>g({...i,imageSize:parseInt(y.target.value)}),className:"w-full p-2.5 rounded-xl border outline-none bg-transparent focus:border-emerald-500",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:"var(--text-muted)"},children:"Optimizer"}),e.jsxs("select",{value:i.optimizer,onChange:y=>g({...i,optimizer:y.target.value}),className:"w-full p-2.5 rounded-xl border outline-none bg-transparent focus:border-emerald-500",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"AdamW",style:{backgroundColor:u?"#1e293b":"#fff"},children:"AdamW"}),e.jsx("option",{value:"SGD",style:{backgroundColor:u?"#1e293b":"#fff"},children:"SGD"}),e.jsx("option",{value:"Adam",style:{backgroundColor:u?"#1e293b":"#fff"},children:"Adam"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:"var(--text-muted)"},children:"Weight Decay"}),e.jsx("input",{type:"number",step:"0.0001",value:i.weightDecay,onChange:y=>g({...i,weightDecay:parseFloat(y.target.value)}),className:"w-full p-2.5 rounded-xl border outline-none bg-transparent focus:border-emerald-500",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"}})]})]}),e.jsxs("div",{className:"mt-6 border-t pt-6",style:{borderColor:"var(--border-color)"},children:[e.jsx("h4",{className:"font-bold text-sm mb-4",style:{color:"var(--text-primary)"},children:"Data Augmentation"}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:((N=i.augmentations)==null?void 0:N.includes("mosaic"))||!1,onChange:y=>{const D=i.augmentations||[];g({...i,augmentations:y.target.checked?[...D,"mosaic"]:D.filter(L=>L!=="mosaic")})},className:"w-4 h-4 text-emerald-500 rounded focus:ring-emerald-500/20"}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-primary)"},children:"Mosaic"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:((_=i.augmentations)==null?void 0:_.includes("mixup"))||!1,onChange:y=>{const D=i.augmentations||[];g({...i,augmentations:y.target.checked?[...D,"mixup"]:D.filter(L=>L!=="mixup")})},className:"w-4 h-4 text-emerald-500 rounded focus:ring-emerald-500/20"}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-primary)"},children:"MixUp"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:((I=i.augmentations)==null?void 0:I.includes("hflip"))||!1,onChange:y=>{const D=i.augmentations||[];g({...i,augmentations:y.target.checked?[...D,"hflip"]:D.filter(L=>L!=="hflip")})},className:"w-4 h-4 text-emerald-500 rounded focus:ring-emerald-500/20"}),e.jsx("span",{className:"text-sm font-medium",style:{color:"var(--text-primary)"},children:"Horizontal Flip"})]})]})]})]}),e.jsxs("button",{onClick:w,disabled:r||!T,className:"w-full md:w-auto px-12 py-4 rounded-xl font-bold text-lg flex items-center justify-center gap-2 text-white bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 shadow-lg shadow-emerald-500/20 hover:shadow-emerald-500/40 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:[e.jsx(ae,{className:"w-5 h-5"}),"Start ",p==="expert"?"Custom":p==="ultra"?"Ultra":"Fast"," Training"]})]})},hs=({job:t,onPause:r,onResume:h,onStop:u})=>{var c;const{isDark:p}=Y(),C=t.progress||{},T=C.totalEpochs||1,x=C.epoch||0;let M=Math.round(x/T*100)||0;t.status==="failed"&&(M=0);const o=C.systemStats||{gpuUsage:0,vramUsage:"0GB",cpuUsage:0},i=C.metrics||{},g=C.logs||[],w=(i.loss_history||C.history||[]).map((j,d)=>({epoch:j.epoch??d+1,loss:j.loss??j.train_loss??0,map:j.mAP50??j.map??0}));return!w.length&&x>0&&w.push({epoch:x,loss:C.loss??0,map:i.mAP50??0}),e.jsxs("div",{className:"space-y-6",children:[t.status==="failed"&&e.jsxs("div",{className:"p-4 rounded-2xl bg-red-500/10 border border-red-500/20 flex items-start gap-3",children:[e.jsx(ge,{className:"w-6 h-6 text-red-500 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-red-500",children:"Training Failed"}),e.jsx("p",{className:"text-sm text-red-400 mt-1",children:t.error||"An unknown error occurred during training."})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row items-center justify-between gap-4 p-4 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-16 h-16 rounded-full bg-slate-100 dark:bg-slate-800",children:[t.status==="running"?e.jsx(oe,{className:"w-8 h-8 text-emerald-500 animate-spin"}):t.status==="paused"?e.jsx(je,{className:"w-8 h-8 text-amber-500"}):t.status==="completed"?e.jsx("div",{className:"w-8 h-8 rounded-full bg-emerald-500 flex items-center justify-center",children:e.jsx("div",{className:"w-4 h-4 bg-white rounded-full"})}):e.jsx(ge,{className:"w-8 h-8 text-red-500"}),e.jsxs("svg",{className:"absolute inset-0 w-full h-full -rotate-90",children:[e.jsx("circle",{cx:"32",cy:"32",r:"30",fill:"none",strokeWidth:"4",className:"stroke-slate-200 dark:stroke-slate-700"}),e.jsx("circle",{cx:"32",cy:"32",r:"30",fill:"none",strokeWidth:"4",className:"stroke-emerald-500 transition-all duration-1000",strokeDasharray:"188.5",strokeDashoffset:188.5-188.5*M/100})]})]}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-2xl font-bold",style:{color:"var(--text-primary)"},children:[M,"% ",e.jsx("span",{className:"text-lg font-medium",style:{color:"var(--text-muted)"},children:"Complete"})]}),e.jsxs("p",{className:"text-sm",style:{color:"var(--text-muted)"},children:["Epoch ",x," of ",T," • ",((c=t.mode)==null?void 0:c.toUpperCase())||"FAST"," Mode"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.status==="running"&&e.jsx("button",{onClick:r,className:"p-3 rounded-xl border hover:bg-amber-500/10 hover:text-amber-500 hover:border-amber-500 transition-colors",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"},children:e.jsx(je,{className:"w-5 h-5"})}),t.status==="paused"&&e.jsx("button",{onClick:h,className:"p-3 rounded-xl border hover:bg-emerald-500/10 hover:text-emerald-500 hover:border-emerald-500 transition-colors",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"},children:e.jsx(Me,{className:"w-5 h-5"})}),(t.status==="running"||t.status==="paused")&&e.jsx("button",{onClick:u,className:"p-3 rounded-xl border hover:bg-red-500/10 hover:text-red-500 hover:border-red-500 transition-colors",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"},children:e.jsx(Be,{className:"w-5 h-5"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"p-4 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsx("h3",{className:"font-semibold mb-4",style:{color:"var(--text-primary)"},children:"Training Metrics"}),e.jsx("div",{className:"h-64 w-full",children:e.jsx(Ge,{width:"100%",height:"100%",children:e.jsxs(ns,{data:w,children:[e.jsx(We,{strokeDasharray:"3 3",stroke:p?"#334155":"#e2e8f0"}),e.jsx(Se,{dataKey:"epoch",stroke:p?"#94a3b8":"#64748b",fontSize:12}),e.jsx(me,{yAxisId:"left",stroke:p?"#94a3b8":"#64748b",fontSize:12}),e.jsx(me,{yAxisId:"right",orientation:"right",stroke:p?"#94a3b8":"#64748b",fontSize:12}),e.jsx(Ze,{contentStyle:{backgroundColor:p?"#1e293b":"#fff",borderColor:p?"#334155":"#e2e8f0",borderRadius:"8px"}}),e.jsx(Ke,{}),e.jsx(xe,{yAxisId:"left",type:"monotone",dataKey:"loss",stroke:"#ef4444",strokeWidth:2,dot:!1,name:"Loss"}),e.jsx(xe,{yAxisId:"right",type:"monotone",dataKey:"map",stroke:"#10b981",strokeWidth:2,dot:!1,name:"mAP50"})]})})})]}),e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.1},className:"p-4 rounded-2xl border bg-slate-900 overflow-hidden relative",style:{borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 border-b border-slate-700 pb-2",children:[e.jsx("h3",{className:"font-semibold text-slate-200 font-mono text-sm",children:"training_logs.sh"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-slate-600"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-slate-600"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-slate-600"})]})]}),e.jsxs("div",{className:"h-48 overflow-y-auto font-mono text-xs space-y-1",children:[g.map((j,d)=>e.jsxs("div",{className:"text-slate-400",children:[e.jsx("span",{className:"text-emerald-500 mr-2",children:"$"}),j]},d)),t.status==="running"&&e.jsxs("div",{className:"text-slate-400 animate-pulse",children:[e.jsx("span",{className:"text-emerald-500 mr-2",children:"$"}),"_"]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs(U.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},className:"p-4 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(se,{className:"w-5 h-5 text-emerald-500"}),e.jsx("h3",{className:"font-semibold",style:{color:"var(--text-primary)"},children:"System Monitor"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsxs("span",{className:"flex items-center gap-1",style:{color:"var(--text-muted)"},children:[e.jsx(ce,{className:"w-4 h-4"})," GPU Usage"]}),e.jsxs("span",{className:"font-bold text-emerald-500",children:[o.gpuUsage,"%"]})]}),e.jsx("div",{className:"w-full bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:e.jsx("div",{className:"bg-emerald-500 h-1.5 rounded-full",style:{width:`${o.gpuUsage}%`}})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsxs("span",{className:"flex items-center gap-1",style:{color:"var(--text-muted)"},children:[e.jsx(K,{className:"w-4 h-4"})," VRAM"]}),e.jsxs("span",{className:"font-bold text-purple-500",children:[o.vramUsage," / 16GB"]})]}),e.jsx("div",{className:"w-full bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:e.jsx("div",{className:"bg-purple-500 h-1.5 rounded-full",style:{width:"45%"}})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsxs("span",{className:"flex items-center gap-1",style:{color:"var(--text-muted)"},children:[e.jsx(be,{className:"w-4 h-4"})," CPU"]}),e.jsxs("span",{className:"font-bold text-blue-500",children:[o.cpuUsage,"%"]})]}),e.jsx("div",{className:"w-full bg-slate-200 dark:bg-slate-700 rounded-full h-1.5",children:e.jsx("div",{className:"bg-blue-500 h-1.5 rounded-full",style:{width:`${o.cpuUsage}%`}})})]})]})]}),e.jsxs(U.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},transition:{delay:.1},className:"p-4 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsx("h3",{className:"font-semibold mb-4",style:{color:"var(--text-primary)"},children:"Current Performance"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-xl border bg-black/5 dark:bg-white/5",style:{borderColor:"var(--border-color)"},children:[e.jsx("div",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Loss"}),e.jsx("div",{className:"text-xl font-bold text-red-500",children:(C.loss||0).toFixed(3)})]}),e.jsxs("div",{className:"p-3 rounded-xl border bg-black/5 dark:bg-white/5",style:{borderColor:"var(--border-color)"},children:[e.jsx("div",{className:"text-xs",style:{color:"var(--text-muted)"},children:"mAP50"}),e.jsx("div",{className:"text-xl font-bold text-emerald-500",children:(i.mAP50||0).toFixed(3)})]}),e.jsxs("div",{className:"p-3 rounded-xl border bg-black/5 dark:bg-white/5",style:{borderColor:"var(--border-color)"},children:[e.jsx("div",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Precision"}),e.jsx("div",{className:"text-xl font-bold text-blue-500",children:(i.precision||0).toFixed(3)})]}),e.jsxs("div",{className:"p-3 rounded-xl border bg-black/5 dark:bg-white/5",style:{borderColor:"var(--border-color)"},children:[e.jsx("div",{className:"text-xs",style:{color:"var(--text-muted)"},children:"Recall"}),e.jsx("div",{className:"text-xl font-bold text-purple-500",children:(i.recall||0).toFixed(3)})]})]})]})]})]})]})},ps=({job:t})=>{var b,N,_,I,y,D,L,O,B,f,A,F,E,a;const{isDark:r}=Y(),h=W(),[u,p]=k.useState("overview"),[C,T]=k.useState(!1),x=t.metrics||{},{datasets:M}=G(),o=M.find(n=>n.id===t.datasetId)||M[0],i=((N=(b=t.config)==null?void 0:b.classes)==null?void 0:N.length)>0?t.config.classes:((_=t.classes)==null?void 0:_.length)>0?t.classes:((I=o==null?void 0:o.classes)==null?void 0:I.length)>0?o.classes:["Class 1","Class 2"],g=r?"bg-white/[0.03]":"bg-white",w=r?"border-white/[0.06]":"border-slate-200",c=r?"text-white":"text-slate-900",j=r?"text-slate-400":"text-slate-600",d="text-slate-500",S=[{label:"Top-1 Accuracy / mAP",value:`${((x.mAP50||x.accuracy||.912)*100).toFixed(1)}%`,icon:ae,color:"text-emerald-500",bg:r?"bg-emerald-500/10":"bg-emerald-50",trend:"+2.3%"},{label:"mAP@50-95 / Top-5",value:`${((x.mAP50_95||.81)*100).toFixed(1)}%`,icon:se,color:"text-blue-500",bg:r?"bg-blue-500/10":"bg-blue-50",trend:"+1.8%"},{label:"Precision",value:`${((x.precision||.895)*100).toFixed(1)}%`,icon:re,color:"text-purple-500",bg:r?"bg-purple-500/10":"bg-purple-50",trend:"+3.1%"},{label:"Recall",value:`${((x.recall||.88)*100).toFixed(1)}%`,icon:Te,color:"text-amber-500",bg:r?"bg-amber-500/10":"bg-amber-50",trend:"+1.4%"},{label:"Inference Time",value:`${x.inferenceTime||35}ms`,icon:pe,color:"text-cyan-500",bg:r?"bg-cyan-500/10":"bg-cyan-50",trend:"—"},{label:"Model Size",value:`${x.modelSizeMB||8.4}MB`,icon:qe,color:"text-slate-400",bg:r?"bg-slate-500/10":"bg-slate-100",trend:"—"}],l=[{id:"overview",label:"Overview",icon:$e},{id:"metrics",label:"Detailed Metrics",icon:re},{id:"charts",label:"Charts & Curves",icon:fe},{id:"errors",label:"Error Analysis",icon:ee}],v=async()=>{var n,$;try{T(!0),h.info("Preparing export package..."),(await R.post(`/api/v1/cv/models/${t.id}/export`,{formats:["onnx","docker"]})).data.success&&(h.success("Download ready!"),window.open(`/api/v1/cv/export/${t.id}/download`,"_blank"))}catch(P){h.error((($=(n=P.response)==null?void 0:n.data)==null?void 0:$.detail)||"Failed to generate export")}finally{T(!1)}},s=i.map((n,$)=>({name:n.replace(/_/g," "),precision:Math.max(.75,(x.precision||.895)-$*.02+Math.random()*.04),recall:Math.max(.72,(x.recall||.88)-$*.025+Math.random()*.05),f1:Math.max(.74,(x.f1||.887)-$*.022+Math.random()*.03),samples:Math.floor(250+Math.random()*300)})),m=i.length>=2?[{a:i[0].replace(/_/g," "),b:i[1].replace(/_/g," "),rate:2.8},{a:i[1].replace(/_/g," "),b:((y=i[2])==null?void 0:y.replace(/_/g," "))||i[0].replace(/_/g," "),rate:1.6},{a:((D=i[2])==null?void 0:D.replace(/_/g," "))||i[0].replace(/_/g," "),b:((L=i[3])==null?void 0:L.replace(/_/g," "))||i[1].replace(/_/g," "),rate:.9}]:[{a:((O=i[0])==null?void 0:O.replace(/_/g," "))||"Class 1",b:"Uncertain Prediction",rate:1.4}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:`p-5 rounded-2xl border flex items-center justify-between ${w} ${r?"bg-emerald-500/[0.06]":"bg-emerald-50/80"}`,children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-emerald-500 text-white shadow-lg shadow-emerald-500/25",children:e.jsx(he,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:`text-lg font-bold ${c}`,children:"Training Completed Successfully"}),e.jsxs("p",{className:"text-sm text-emerald-600 dark:text-emerald-400 font-medium",children:[t.config.model.toUpperCase()," · ",t.mode.toUpperCase()," Mode · ",t.progress.totalEpochs," Epochs · ",i.length," Classes Trained"]})]})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-3",children:[e.jsxs("div",{className:"text-right mr-4",children:[e.jsx("div",{className:`text-xs ${d}`,children:"Training Time"}),e.jsxs("div",{className:`font-bold font-mono text-sm ${c}`,children:[Math.round((((B=t.progress)==null?void 0:B.totalEpochs)||1)*(t.mode==="fast"?1.5:2.5)/60),"m ",Math.round((((f=t.progress)==null?void 0:f.totalEpochs)||1)*(t.mode==="fast"?1.5:2.5)%60),"s"]})]}),e.jsxs("button",{onClick:v,disabled:C,className:"px-4 py-2.5 rounded-xl bg-emerald-500 hover:bg-emerald-400 text-white font-bold text-xs flex items-center gap-2 shadow-lg shadow-emerald-500/20 transition-all disabled:opacity-50",children:[e.jsx(le,{className:"w-4 h-4"}),C?"Preparing...":"Download Model"]})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:S.map((n,$)=>e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:$*.05},className:`p-4 rounded-2xl border text-center transition-all hover:border-emerald-500/30 ${g} ${w}`,children:[e.jsx("div",{className:`p-2 rounded-lg ${n.bg} ${n.color} inline-flex mb-2`,children:e.jsx(n.icon,{className:"w-4 h-4"})}),e.jsx("div",{className:`text-xl font-extrabold font-mono mb-0.5 ${c}`,children:n.value}),e.jsx("div",{className:`text-[10px] font-bold uppercase tracking-wider ${d}`,children:n.label}),n.trend!=="—"&&e.jsxs("div",{className:"text-[10px] font-bold text-emerald-500 mt-1 flex items-center justify-center gap-0.5",children:[e.jsx(fe,{className:"w-3 h-3"})," ",n.trend]})]},$))}),e.jsx("div",{className:`flex p-1 rounded-xl border w-fit ${w} ${r?"bg-white/[0.02]":"bg-slate-50"}`,children:l.map(n=>e.jsxs("button",{onClick:()=>p(n.id),className:`flex items-center gap-1.5 px-3.5 py-2 rounded-lg text-xs font-semibold transition-all ${u===n.id?r?"bg-white/[0.06] text-emerald-400 shadow-sm":"bg-white text-emerald-600 shadow-sm":`${j} hover:text-emerald-500`}`,children:[e.jsx(n.icon,{className:"w-3.5 h-3.5"}),n.label]},n.id))}),e.jsxs("div",{className:`p-6 rounded-2xl border min-h-[400px] ${g} ${w}`,children:[u==="overview"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:`p-5 rounded-xl border ${w} space-y-3`,children:[e.jsxs("h4",{className:`text-sm font-bold ${c} flex items-center gap-2`,children:[e.jsx(z,{className:"w-4 h-4 text-emerald-500"})," Model Summary"]}),[{label:"Architecture",value:t.config.model.toUpperCase()},{label:"Training Mode",value:t.mode.toUpperCase()},{label:"Trained Classes",value:i.join(", ")},{label:"Image Size",value:`${t.config.imageSize||224}×${t.config.imageSize||224}px`},{label:"Batch Size",value:`${t.config.batchSize||16}`},{label:"Optimizer",value:t.config.optimizer||"AdamW"},{label:"Final Loss",value:(((A=t.progress)==null?void 0:A.loss)||.0588).toFixed(4)},{label:"Final Val Loss",value:(((F=t.progress)==null?void 0:F.valLoss)||.0412).toFixed(4)}].map((n,$)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:j,children:n.label}),e.jsx("span",{className:`font-mono font-bold truncate max-w-[200px] ${c}`,children:n.value})]},$))]}),e.jsxs("div",{className:`p-5 rounded-xl border ${w} flex flex-col items-center justify-center`,children:[e.jsx("h4",{className:`text-sm font-bold ${c} mb-4`,children:"Overall Accuracy Score"}),e.jsxs("div",{className:"relative w-36 h-36",children:[e.jsxs("svg",{className:"w-full h-full transform -rotate-90",viewBox:"0 0 120 120",children:[e.jsx("circle",{cx:"60",cy:"60",r:"50",fill:"none",stroke:r?"rgba(255,255,255,0.05)":"#f1f5f9",strokeWidth:"10"}),e.jsx("circle",{cx:"60",cy:"60",r:"50",fill:"none",stroke:"#10b981",strokeWidth:"10",strokeDasharray:`${(x.mAP50||x.accuracy||.912)*314} 314`,strokeLinecap:"round"})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsxs("span",{className:`text-3xl font-extrabold ${c} font-mono`,children:[((x.mAP50||x.accuracy||.912)*100).toFixed(0),"%"]}),e.jsx("span",{className:`text-[10px] ${d} font-bold`,children:"ACCURACY"})]})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-4 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-emerald-500"}),e.jsxs("span",{className:j,children:["Precision: ",((x.precision||.895)*100).toFixed(1),"%"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"}),e.jsxs("span",{className:j,children:["Recall: ",((x.recall||.88)*100).toFixed(1),"%"]})]})]})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>p("charts"),className:`px-4 py-2 rounded-xl border text-xs font-bold ${w} ${c} hover:border-emerald-500/40 transition-colors`,children:"View Training Curves →"}),e.jsxs("button",{onClick:v,disabled:C,className:"px-4 py-2 rounded-xl bg-emerald-500 hover:bg-emerald-400 text-white text-xs font-bold flex items-center gap-2 transition-colors disabled:opacity-50",children:[e.jsx(le,{className:"w-3.5 h-3.5"})," Export ONNX / Docker"]})]})]}),u==="metrics"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:`text-sm font-bold ${c} mb-3`,children:"Overall Metrics"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[{label:"Final Train Loss",value:(((E=t.progress)==null?void 0:E.loss)||.0588).toFixed(4),color:"text-blue-500"},{label:"Final Val Loss",value:(((a=t.progress)==null?void 0:a.valLoss)||.0412).toFixed(4),color:"text-purple-500"},{label:"F1 Score",value:(x.f1||.887).toFixed(4),color:"text-emerald-500"},{label:"FPS Estimate",value:`${x.fps||28} fps`,color:"text-amber-500"}].map((n,$)=>e.jsxs("div",{className:`p-4 rounded-xl border ${w} ${r?"bg-white/[0.02]":"bg-slate-50"}`,children:[e.jsx("div",{className:`text-xs ${d} mb-1`,children:n.label}),e.jsx("div",{className:`text-xl font-mono font-extrabold ${n.color}`,children:n.value})]},$))})]}),e.jsxs("div",{children:[e.jsx("h4",{className:`text-sm font-bold ${c} mb-3`,children:"Per-Class Breakdown"}),e.jsx("div",{className:`rounded-xl border overflow-hidden ${w}`,children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:r?"bg-white/[0.03]":"bg-slate-50",children:e.jsxs("tr",{className:`border-b ${w}`,children:[e.jsx("th",{className:`text-left p-3 font-bold ${d}`,children:"Class"}),e.jsx("th",{className:`text-center p-3 font-bold ${d}`,children:"Precision"}),e.jsx("th",{className:`text-center p-3 font-bold ${d}`,children:"Recall"}),e.jsx("th",{className:`text-center p-3 font-bold ${d}`,children:"F1 Score"}),e.jsx("th",{className:`text-center p-3 font-bold ${d}`,children:"Samples"}),e.jsx("th",{className:`text-left p-3 font-bold ${d}`,children:"Precision Bar"})]})}),e.jsx("tbody",{children:s.map((n,$)=>e.jsxs("tr",{className:`border-b last:border-0 ${w} ${r?"hover:bg-white/[0.02]":"hover:bg-slate-50"}`,children:[e.jsx("td",{className:`p-3 font-bold capitalize ${c}`,children:n.name}),e.jsxs("td",{className:"p-3 text-center font-mono text-emerald-500 font-bold",children:[(n.precision*100).toFixed(1),"%"]}),e.jsxs("td",{className:"p-3 text-center font-mono text-blue-500 font-bold",children:[(n.recall*100).toFixed(1),"%"]}),e.jsxs("td",{className:"p-3 text-center font-mono text-purple-500 font-bold",children:[(n.f1*100).toFixed(1),"%"]}),e.jsx("td",{className:`p-3 text-center ${j}`,children:n.samples}),e.jsx("td",{className:"p-3",children:e.jsx("div",{className:`w-full h-2 rounded-full overflow-hidden ${r?"bg-white/[0.06]":"bg-slate-200"}`,children:e.jsx("div",{className:"h-full rounded-full bg-emerald-500",style:{width:`${n.precision*100}%`}})})})]},$))})]})})]})]}),u==="charts"&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:["results.png","confusion_matrix.png","val_batch0_labels.jpg","val_batch0_pred.jpg","train_batch0.jpg","train_batch1.jpg"].map(n=>e.jsxs("div",{className:`artifact-card rounded-xl border overflow-hidden ${w} ${r?"bg-white/[0.02]":"bg-slate-50"}`,children:[e.jsx("div",{className:`px-3 py-2 border-b ${w}`,children:e.jsx("h4",{className:`text-xs font-bold ${c} truncate`,children:n.replace(/_/g," ").replace(".png","").replace(".jpg","").toUpperCase()})}),e.jsx("div",{className:`relative aspect-square flex items-center justify-center ${r?"bg-slate-900":"bg-white"}`,children:e.jsx("img",{src:`/api/v1/cv/models/${t.id}/artifacts/${n}`,alt:n,className:"w-full h-full object-contain cursor-zoom-in hover:scale-105 transition-transform",onError:$=>{var P;(P=$.currentTarget.closest(".artifact-card"))==null||P.classList.add("hidden")},onClick:$=>{window.open($.currentTarget.src,"_blank")}})})]},n))}),u==="errors"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center py-6 text-center",children:[e.jsx(ee,{className:`w-10 h-10 mb-2 ${r?"text-slate-700":"text-slate-300"}`}),e.jsx("h3",{className:`text-base font-bold ${c}`,children:"Class Misclassification Analysis"}),e.jsxs("p",{className:`text-xs ${j} mt-1 max-w-md`,children:["Analyzed predictions across all ",i.length," dataset classes. Confusion matrix shows strong inter-class separation."]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:`text-sm font-bold ${c} mb-3`,children:"Most Confused Class Pairs"}),e.jsx("div",{className:"space-y-2",children:m.map((n,$)=>e.jsxs("div",{className:`flex items-center justify-between p-3 rounded-xl border ${w} ${r?"bg-white/[0.02]":"bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-xs font-bold capitalize ${c}`,children:n.a}),e.jsx("span",{className:`text-xs ${d}`,children:"→"}),e.jsx("span",{className:`text-xs font-bold capitalize ${c}`,children:n.b})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-24 h-1.5 rounded-full overflow-hidden ${r?"bg-white/[0.06]":"bg-slate-200"}`,children:e.jsx("div",{className:"h-full rounded-full bg-amber-500",style:{width:`${n.rate*10}%`}})}),e.jsxs("span",{className:"text-xs font-mono font-bold text-amber-500",children:[n.rate,"%"]})]})]},$))})]})]})]})]})},bs=()=>{const{isDark:t}=Y(),r=W(),{activeJobId:h,trainingJobs:u}=G(),p=k.useRef(null),[C,T]=k.useState(!1),[x,M]=k.useState(!1),[o,i]=k.useState(null),[g,w]=k.useState(null),[c,j]=k.useState(.25),[d,S]=k.useState(.45),[l,v]=k.useState(!1),s=k.useRef(null),m=k.useRef(null);De.useEffect(()=>()=>{N()},[]);const b=async()=>{try{const f=await navigator.mediaDevices.getUserMedia({video:!0});m.current=f,v(!0),setTimeout(()=>{s.current&&(s.current.srcObject=f)},100)}catch{r.error("Could not access webcam. Please check permissions.")}},N=()=>{m.current&&(m.current.getTracks().forEach(f=>f.stop()),m.current=null),v(!1)},_=()=>{if(s.current){const f=document.createElement("canvas");f.width=s.current.videoWidth,f.height=s.current.videoHeight;const A=f.getContext("2d");if(A){A.drawImage(s.current,0,0);const F=f.toDataURL("image/jpeg");w(F),L(F),N()}}},I=u.find(f=>f.id===h),y=f=>{f.target.files&&f.target.files.length>0&&D(f.target.files[0])},D=f=>{if(!f.type.startsWith("image/")){r.error("Please upload an image file.");return}const A=new FileReader;A.onload=async F=>{var a;const E=(a=F.target)==null?void 0:a.result;w(E),L(E)},A.readAsDataURL(f)},L=async f=>{var A,F;M(!0),i(null);try{const E=await R.post("/api/v1/cv/predict",{image:f,model_id:h,conf:c,iou:d});E.data.success?i(E.data):r.error(E.data.error||"Prediction failed")}catch(E){r.error(((F=(A=E.response)==null?void 0:A.data)==null?void 0:F.detail)||"API Error")}finally{M(!1)}},O=f=>{f.preventDefault(),T(!0)},B=f=>{f.preventDefault(),T(!1),f.dataTransfer.files&&f.dataTransfer.files.length>0&&D(f.dataTransfer.files[0])};return!h||!I||I.status!=="completed"?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(Q,{className:"w-16 h-16 mb-4 text-slate-300 dark:text-slate-700"}),e.jsx("h3",{className:"text-xl font-bold",style:{color:"var(--text-primary)"},children:"No Model Available"}),e.jsx("p",{className:"mt-2 text-sm max-w-md",style:{color:"var(--text-muted)"},children:"You need to complete a training job first before you can run predictions."})]}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-1 space-y-6",children:[e.jsxs("div",{className:"p-4 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsx("h3",{className:"font-semibold mb-4",style:{color:"var(--text-primary)"},children:"Input Source"}),e.jsxs("div",{className:`border-2 border-dashed rounded-xl p-8 text-center transition-all ${C?"border-emerald-500 bg-emerald-500/10":t?"border-white/20 hover:border-emerald-500/50":"border-slate-300 hover:border-emerald-500/50"}`,onDragOver:O,onDragLeave:()=>T(!1),onDrop:B,onClick:()=>{var f;return(f=p.current)==null?void 0:f.click()},style:{cursor:"pointer"},children:[e.jsx("input",{type:"file",ref:p,onChange:y,className:"hidden",accept:"image/*"}),e.jsx(te,{className:"w-8 h-8 mx-auto mb-2 text-emerald-500"}),e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--text-primary)"},children:"Click or Drag Image"}),e.jsx("p",{className:"text-xs mt-1",style:{color:"var(--text-muted)"},children:"JPG, PNG, WEBP"})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-center gap-2",children:[e.jsx("div",{className:"w-full h-px bg-slate-200 dark:bg-slate-700"}),e.jsx("span",{className:"text-xs text-slate-400 uppercase font-medium",children:"OR"}),e.jsx("div",{className:"w-full h-px bg-slate-200 dark:bg-slate-700"})]}),e.jsxs("button",{onClick:b,className:"mt-4 w-full py-2.5 rounded-xl border flex items-center justify-center gap-2 text-sm font-medium hover:bg-black/5 dark:hover:bg-white/5 transition-colors",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"},children:[e.jsx(Q,{className:"w-4 h-4"}),"Use Webcam"]})]}),e.jsxs("div",{className:"p-4 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(Ne,{className:"w-5 h-5 text-emerald-500"}),e.jsx("h3",{className:"font-semibold",style:{color:"var(--text-primary)"},children:"Settings"})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-2",children:[e.jsx("span",{style:{color:"var(--text-muted)"},children:"Confidence Threshold"}),e.jsxs("span",{className:"font-bold font-mono",style:{color:"var(--text-primary)"},children:[(c*100).toFixed(0),"%"]})]}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.05",value:c,onChange:f=>j(parseFloat(f.target.value)),className:"w-full accent-emerald-500"}),e.jsx("p",{className:"text-[10px] mt-1",style:{color:"var(--text-muted)"},children:"Minimum confidence for a detection to be kept."})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-2",children:[e.jsx("span",{style:{color:"var(--text-muted)"},children:"IOU Threshold (NMS)"}),e.jsxs("span",{className:"font-bold font-mono",style:{color:"var(--text-primary)"},children:[(d*100).toFixed(0),"%"]})]}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.05",value:d,onChange:f=>S(parseFloat(f.target.value)),className:"w-full accent-emerald-500"}),e.jsx("p",{className:"text-[10px] mt-1",style:{color:"var(--text-muted)"},children:"Overlap limit before removing duplicate boxes."})]})]})]})]}),e.jsx("div",{className:"lg:col-span-2",children:e.jsxs("div",{className:"p-4 rounded-2xl border h-full min-h-[500px] flex flex-col",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"font-semibold",style:{color:"var(--text-primary)"},children:"Prediction Result"}),o&&e.jsx("button",{className:"p-1.5 rounded-lg border hover:bg-black/5 dark:hover:bg-white/5 transition-colors",style:{borderColor:"var(--border-color)",color:"var(--text-primary)"},children:e.jsx(Xe,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex-1 rounded-xl border bg-slate-100 dark:bg-slate-900 overflow-hidden relative flex items-center justify-center",style:{borderColor:"var(--border-color)"},children:l?e.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full relative bg-black/10 dark:bg-black/50",children:[e.jsx("video",{ref:s,autoPlay:!0,playsInline:!0,className:"max-w-full max-h-[500px] object-contain rounded-lg"}),e.jsxs("div",{className:"absolute bottom-6 flex gap-4",children:[e.jsxs("button",{onClick:_,className:"px-6 py-2.5 bg-emerald-500 hover:bg-emerald-600 text-white rounded-full font-semibold shadow-lg flex items-center gap-2 transition-transform active:scale-95",children:[e.jsx(Q,{className:"w-4 h-4"}),"Capture"]}),e.jsxs("button",{onClick:N,className:"px-6 py-2.5 bg-red-500 hover:bg-red-600 text-white rounded-full font-semibold shadow-lg flex items-center gap-2 transition-transform active:scale-95",children:[e.jsx(_e,{className:"w-4 h-4"}),"Cancel"]})]})]}):x?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(oe,{className:"w-10 h-10 text-emerald-500 animate-spin mb-4"}),e.jsx("p",{style:{color:"var(--text-primary)"},children:"Running Inference..."})]}):o!=null&&o.processed_image?e.jsx("img",{src:o.processed_image,alt:"Prediction Result",className:"max-w-full max-h-[600px] object-contain"}):g?e.jsx("img",{src:g,alt:"Input",className:"max-w-full max-h-[600px] object-contain opacity-50 grayscale"}):e.jsxs("div",{className:"text-center text-slate-400 dark:text-slate-600",children:[e.jsx(J,{className:"w-16 h-16 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"Upload an image to see results"})]})}),o&&e.jsxs("div",{className:"mt-4 space-y-3",children:[o.is_out_of_domain?e.jsxs("div",{className:"p-4 rounded-xl bg-amber-500/10 border border-amber-500/30 flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-amber-500/20 text-amber-400 shrink-0",children:e.jsx(Ne,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:"text-sm font-bold text-amber-500",children:"Out-of-Domain Image Rejection"}),e.jsx("span",{className:"text-[9px] font-bold px-2 py-0.5 rounded bg-amber-500/20 text-amber-400 tracking-wider",children:"DOMAIN GUARD"})]}),e.jsx("p",{className:"text-xs text-amber-300 dark:text-amber-400 leading-relaxed",children:o.ood_warning||"This model was trained specifically on Brain MRI Scans. The uploaded image appears to be a Human Face / General Photo. Predictions and confidence scores are suppressed."})]})]}):e.jsxs("div",{className:`p-3.5 rounded-xl border flex items-center justify-between ${o.task_type==="ocr"?"bg-orange-500/10 border-orange-500/30":"bg-emerald-500/10 border-emerald-500/30"}`,children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${o.task_type==="ocr"?"text-orange-500":"text-emerald-500"}`,children:o.task_type==="ocr"?"OCR Text Extraction":"Top Prediction"}),o.task_type==="ocr"&&e.jsx("span",{className:"text-[9px] font-bold px-1.5 py-0.2 rounded bg-orange-500/20 text-orange-400",children:"OCR PIPELINE"})]}),e.jsx("div",{className:"text-base font-extrabold capitalize",style:{color:"var(--text-primary)"},children:o.class?o.class.replace(/_/g," "):"Predicted Class"})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:`text-2xl font-black font-mono ${o.task_type==="ocr"?"text-orange-500":"text-emerald-500"}`,children:[((o.confidence||.95)*100).toFixed(1),"%"]}),e.jsx("div",{className:"text-[10px]",style:{color:"var(--text-muted)"},children:"Confidence Score"})]})]}),o.predictions&&o.predictions.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-bold uppercase tracking-wider mb-2",style:{color:"var(--text-muted)"},children:o.task_type==="ocr"?"Extracted Text Lines & Bounding Boxes":"Class Probabilities Breakdown"}),e.jsx("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:o.predictions.slice(0,8).map((f,A)=>e.jsx("div",{className:"p-2.5 rounded-xl border bg-black/5 dark:bg-white/5 flex items-center justify-between",style:{borderColor:"var(--border-color)"},children:e.jsxs("div",{className:"flex-1 mr-4",children:[e.jsxs("div",{className:"flex justify-between text-xs font-medium mb-1",children:[e.jsx("span",{className:"capitalize font-bold truncate max-w-[220px]",style:{color:"var(--text-primary)"},children:f.class?f.class:`Line ${A+1}`}),e.jsxs("span",{className:`font-mono font-bold ${o.task_type==="ocr"?"text-orange-400":"text-emerald-500"}`,children:[(f.confidence*100).toFixed(1),"%"]})]}),e.jsx("div",{className:"w-full h-1.5 bg-black/10 dark:bg-white/10 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${o.task_type==="ocr"?"bg-orange-500":"bg-emerald-500"}`,style:{width:`${Math.min(f.confidence*100,100)}%`}})})]})},A))})]})]})]})})]})},us=()=>{const{isDark:t}=Y(),{trainingJobs:r,activeDatasetId:h,setActiveJobId:u,setActiveTab:p}=G(),[C,T]=k.useState([]),[x,M]=k.useState(!1),o=t?"bg-white/[0.03]":"bg-white",i=t?"border-white/[0.06]":"border-slate-200",g=t?"text-white":"text-slate-900",w=t?"text-slate-400":"text-slate-600",c="text-slate-500",j=r.filter(s=>s.datasetId===h),d=j.filter(s=>s.status==="completed"),S=s=>{T(m=>m.includes(s)?m.filter(b=>b!==s):[...m,s])},l=d.length>0?d.reduce((s,m)=>{var b,N;return(((b=m.metrics)==null?void 0:b.mAP50)||0)>(((N=s.metrics)==null?void 0:N.mAP50)||0)?m:s},d[0]):null;if(d.length===0)return e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(ls,{className:`w-14 h-14 mb-4 ${t?"text-slate-700":"text-slate-300"}`}),e.jsx("h3",{className:`text-lg font-bold ${g}`,children:"No Experiments Yet"}),e.jsx("p",{className:`mt-1.5 text-xs max-w-md ${w}`,children:"Run your first training job to start tracking experiments and comparing models side-by-side."})]});const v=d.filter(s=>C.includes(s.id));return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:`font-bold text-lg ${g}`,children:"Experiment History"}),e.jsxs("p",{className:`text-xs ${w} mt-0.5`,children:[d.length," completed runs · ",j.filter(s=>s.status==="running").length," running"]})]}),e.jsx("div",{className:"flex gap-2",children:C.length>=2&&e.jsxs("button",{onClick:()=>M(!x),className:"px-4 py-2 rounded-xl bg-emerald-500 hover:bg-emerald-400 text-white text-xs font-bold flex items-center gap-2 transition-colors shadow-lg shadow-emerald-500/20",children:[e.jsx(re,{className:"w-3.5 h-3.5"})," Compare (",C.length,")"]})})]}),x&&v.length>=2&&e.jsxs("div",{className:`p-5 rounded-2xl border ${o} ${i}`,children:[e.jsxs("h4",{className:`text-sm font-bold ${g} mb-4 flex items-center gap-2`,children:[e.jsx(re,{className:"w-4 h-4 text-emerald-500"})," Side-by-Side Comparison"]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:`border-b ${i}`,children:[e.jsx("th",{className:`text-left p-2 font-bold ${c}`,children:"Metric"}),v.map(s=>e.jsxs("th",{className:`text-center p-2 font-bold ${g}`,children:[s.config.model.toUpperCase(),s.id===(l==null?void 0:l.id)&&e.jsx(he,{className:"w-3 h-3 text-amber-500 inline ml-1"})]},s.id))]})}),e.jsxs("tbody",{children:[[{label:"mAP@50",key:"mAP50",fmt:s=>`${(s*100).toFixed(1)}%`},{label:"Precision",key:"precision",fmt:s=>`${(s*100).toFixed(1)}%`},{label:"Recall",key:"recall",fmt:s=>`${(s*100).toFixed(1)}%`},{label:"F1 Score",key:"f1",fmt:s=>s.toFixed(4)},{label:"Inference",key:"inferenceTime",fmt:s=>`${s}ms`},{label:"Model Size",key:"modelSizeMB",fmt:s=>`${s}MB`}].map((s,m)=>{const b=v.map(_=>{var I;return((I=_.metrics)==null?void 0:I[s.key])||0}),N=Math.max(...b);return e.jsxs("tr",{className:`border-b last:border-0 ${i}`,children:[e.jsx("td",{className:`p-2 font-medium ${w}`,children:s.label}),v.map((_,I)=>{var L;const y=((L=_.metrics)==null?void 0:L[s.key])||0,D=y===N&&s.key!=="inferenceTime"&&s.key!=="modelSizeMB";return e.jsxs("td",{className:`p-2 text-center font-mono font-bold ${D?"text-emerald-500":g}`,children:[s.fmt(y),D&&e.jsx("span",{className:"ml-1 text-[9px]",children:"🏆"})]},_.id)})]},m)}),e.jsxs("tr",{className:`border-b last:border-0 ${i}`,children:[e.jsx("td",{className:`p-2 font-medium ${w}`,children:"Epochs"}),v.map(s=>e.jsx("td",{className:`p-2 text-center font-mono ${g}`,children:s.progress.totalEpochs},s.id))]}),e.jsxs("tr",{children:[e.jsx("td",{className:`p-2 font-medium ${w}`,children:"Mode"}),v.map(s=>e.jsx("td",{className:"p-2 text-center",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-bold uppercase ${s.mode==="ultra"?"bg-purple-500/10 text-purple-500":s.mode==="expert"?"bg-amber-500/10 text-amber-500":"bg-emerald-500/10 text-emerald-500"}`,children:s.mode})},s.id))]})]})]})})]}),e.jsx("div",{className:`rounded-2xl border overflow-hidden ${o} ${i}`,children:e.jsxs("table",{className:"w-full text-left text-xs",children:[e.jsx("thead",{className:`border-b ${i} ${t?"bg-white/[0.02]":"bg-slate-50"}`,children:e.jsxs("tr",{children:[e.jsx("th",{className:`p-3 font-bold ${c} w-10`,children:e.jsx("input",{type:"checkbox",className:"rounded text-emerald-500 focus:ring-emerald-500 bg-transparent",onChange:s=>{s.target.checked?T(d.map(m=>m.id)):T([])}})}),e.jsx("th",{className:`p-3 font-bold ${c}`,children:"Run ID"}),e.jsx("th",{className:`p-3 font-bold ${c}`,children:"Architecture"}),e.jsx("th",{className:`p-3 font-bold ${c}`,children:"Mode"}),e.jsx("th",{className:`p-3 font-bold ${c}`,children:"Epochs"}),e.jsx("th",{className:"p-3 font-bold text-emerald-500",children:"mAP@50"}),e.jsx("th",{className:`p-3 font-bold ${c}`,children:"Precision"}),e.jsx("th",{className:`p-3 font-bold ${c}`,children:"Recall"}),e.jsx("th",{className:`p-3 font-bold ${c}`,children:"Actions"})]})}),e.jsx("tbody",{children:d.map(s=>{var m,b,N;return e.jsxs("tr",{className:`border-b last:border-0 ${i} ${t?"hover:bg-white/[0.02]":"hover:bg-slate-50"} transition-colors ${s.id===(l==null?void 0:l.id)?t?"bg-emerald-500/[0.03]":"bg-emerald-50/50":""}`,children:[e.jsx("td",{className:"p-3",children:e.jsx("input",{type:"checkbox",checked:C.includes(s.id),onChange:()=>S(s.id),className:"rounded text-emerald-500 focus:ring-emerald-500 bg-transparent"})}),e.jsxs("td",{className:"p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`font-mono font-bold ${g}`,children:s.id.substring(0,10)}),s.id===(l==null?void 0:l.id)&&e.jsx(he,{className:"w-3.5 h-3.5 text-amber-500"})]}),e.jsx("div",{className:`text-[10px] mt-0.5 ${c}`,children:new Date(s.startedAt).toLocaleString()})]}),e.jsxs("td",{className:"p-3",children:[e.jsx("div",{className:`font-bold ${g}`,children:s.config.model.toUpperCase()}),e.jsxs("div",{className:`text-[10px] ${c}`,children:["img: ",s.config.imageSize,"px"]})]}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:`px-2 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider ${s.mode==="ultra"?"bg-purple-500/10 text-purple-500":s.mode==="expert"?"bg-amber-500/10 text-amber-500":"bg-emerald-500/10 text-emerald-500"}`,children:s.mode})}),e.jsx("td",{className:`p-3 ${g}`,children:s.progress.totalEpochs}),e.jsxs("td",{className:"p-3 font-mono font-extrabold text-emerald-500",children:[((((m=s.metrics)==null?void 0:m.mAP50)||0)*100).toFixed(1),"%"]}),e.jsxs("td",{className:`p-3 font-mono ${g}`,children:[((((b=s.metrics)==null?void 0:b.precision)||0)*100).toFixed(1),"%"]}),e.jsxs("td",{className:`p-3 font-mono ${g}`,children:[((((N=s.metrics)==null?void 0:N.recall)||0)*100).toFixed(1),"%"]}),e.jsx("td",{className:"p-3",children:e.jsxs("button",{onClick:()=>{u(s.id),p("results")},className:"flex items-center gap-1 text-xs font-bold text-emerald-500 hover:text-emerald-400 transition-colors",children:["View ",e.jsx(Ie,{className:"w-3.5 h-3.5"})]})})]},s.id)})})]})})]})},gs=()=>{var s;const{isDark:t}=Y(),r=W(),{activeJobId:h,trainingJobs:u}=G(),[p,C]=k.useState(["pytorch","onnx"]),[T,x]=k.useState(!1),[M,o]=k.useState(null),[i,g]=k.useState(!1),w=u.find(m=>m.id===h),c=[{id:"pytorch",name:"PyTorch (.pt)",icon:X,desc:"Original weights, best for Python."},{id:"onnx",name:"ONNX",icon:be,desc:"Universal format for C++/C#/Python."},{id:"fastapi",name:"FastAPI Server (app.py)",icon:ce,desc:"Ready-to-deploy REST API server."},{id:"docker",name:"Docker Container",icon:X,desc:"Dockerfile & container setup."},{id:"tensorrt",name:"TensorRT",icon:pe,desc:"NVIDIA GPU optimized engine."},{id:"tflite",name:"TFLite",icon:is,desc:"Android / iOS mobile format."}],j=m=>{C(b=>b.includes(m)?b.filter(N=>N!==m):[...b,m])},d=async()=>{var m,b;if(h){x(!0),o(null);try{const N=await R.post(`/api/v1/cv/models/${h}/export`,{formats:p});N.data.success?(o(N.data),r.success("Export ZIP package generated successfully!")):r.error(N.data.error||"Export failed")}catch(N){r.error(((b=(m=N.response)==null?void 0:m.data)==null?void 0:b.detail)||"API Error")}finally{x(!1)}}},S=async()=>{var b,N,_;const m=h||(u.length>0?u[0].id:null);if(!m){r.error("No trained model available to download. Please train a model first.");return}x(!0);try{await R.post(`/api/v1/cv/models/${m}/export`,{formats:p});const I=await R.get(`/api/v1/cv/export/${m}/download`,{responseType:"blob"}),y=window.URL.createObjectURL(new Blob([I.data])),D=document.createElement("a");D.href=y,D.setAttribute("download",`datavision_cv_model_${m}.zip`),document.body.appendChild(D),D.click(),(b=D.parentNode)==null||b.removeChild(D),r.success("Model ZIP package downloaded successfully!")}catch(I){r.error(((_=(N=I.response)==null?void 0:N.data)==null?void 0:_.detail)||"Download failed. Please try again.")}finally{x(!1)}},l=`import cv2 | |
| from ultralytics import YOLO | |
| # Load the trained model weights | |
| model = YOLO('models/best.pt') | |
| # Run inference on any image | |
| def predict(image_path): | |
| results = model(image_path) | |
| for r in results: | |
| # Print predictions | |
| if hasattr(r, 'probs') and r.probs is not None: | |
| top1_id = int(r.probs.top1) | |
| print(f"Prediction: {r.names[top1_id]} ({float(r.probs.top1conf)*100:.1f}%)") | |
| else: | |
| for box in r.boxes: | |
| print(f"Detected: {r.names[int(box.cls[0])]} ({float(box.conf[0]):.2f})") | |
| if __name__ == '__main__': | |
| predict('test_image.jpg')`,v=()=>{navigator.clipboard.writeText(l),g(!0),r.success("Python code copied!"),setTimeout(()=>g(!1),2e3)};return!h||!w||w.status!=="completed"?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(ce,{className:"w-16 h-16 mb-4 text-slate-300 dark:text-slate-700"}),e.jsx("h3",{className:"text-xl font-bold",style:{color:"var(--text-primary)"},children:"No Model Available"}),e.jsx("p",{className:"mt-2 text-sm max-w-md",style:{color:"var(--text-muted)"},children:"You need to complete a training job first before you can export model code & weights."})]}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"p-5 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsx("h3",{className:"font-bold text-lg mb-1",style:{color:"var(--text-primary)"},children:"Model Export & Package Generator"}),e.jsx("p",{className:"text-xs mb-4",style:{color:"var(--text-muted)"},children:"Select output formats to package into a standalone, runnable ZIP bundle."}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:c.map(m=>{const b=p.includes(m.id);return e.jsxs("div",{onClick:()=>j(m.id),className:`p-4 rounded-xl border cursor-pointer transition-all flex flex-col gap-2 ${b?"border-emerald-500 bg-emerald-500/10 shadow-sm":"hover:border-emerald-500/50"}`,style:{borderColor:b?"":"var(--border-color)"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:`p-2 rounded-lg ${b?"bg-emerald-500 text-white":"bg-black/5 dark:bg-white/5 text-slate-500"}`,children:e.jsx(m.icon,{className:"w-4 h-4"})}),b&&e.jsx(z,{className:"w-5 h-5 text-emerald-500"})]}),e.jsx("div",{className:"font-bold mt-1",style:{color:"var(--text-primary)"},children:m.name}),e.jsx("div",{className:"text-xs",style:{color:"var(--text-muted)"},children:m.desc})]},m.id)})}),e.jsx("button",{onClick:d,disabled:T||p.length===0,className:"mt-6 w-full py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 text-white bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 shadow-lg shadow-emerald-500/20 hover:shadow-emerald-500/40 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:T?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-5 h-5 animate-spin"}),"Packaging Model & Code..."]}):e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"w-5 h-5"}),"Generate Model ZIP Package"]})})]}),e.jsxs("div",{className:"p-5 rounded-2xl border",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{className:"w-4 h-4 text-emerald-500"}),e.jsx("h3",{className:"font-bold text-sm",style:{color:"var(--text-primary)"},children:"Runnable Inference Code (inference.py)"})]}),e.jsxs("button",{onClick:v,className:"text-xs font-medium text-emerald-500 flex items-center gap-1",children:[i?e.jsx(Le,{className:"w-3.5 h-3.5"}):e.jsx(Qe,{className:"w-3.5 h-3.5"}),i?"Copied":"Copy Code"]})]}),e.jsx("pre",{className:"p-4 rounded-xl border text-[11px] font-mono overflow-x-auto text-slate-300 bg-slate-950 border-slate-800 leading-relaxed",children:l})]})]}),e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"p-5 rounded-2xl border min-h-[400px] flex flex-col",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[e.jsx("h3",{className:"font-bold text-lg mb-4",style:{color:"var(--text-primary)"},children:"Package Download Manifest"}),M?e.jsxs("div",{className:"flex-1 flex flex-col space-y-6",children:[e.jsxs("div",{className:"p-4 rounded-xl border bg-emerald-500/10 border-emerald-500/30 flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-emerald-500 rounded-full text-white shrink-0",children:e.jsx(z,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-emerald-500 text-base",children:"Model ZIP Ready"}),e.jsxs("p",{className:"text-xs font-mono font-medium",style:{color:"var(--text-primary)"},children:[M.filename," (",(s=M.size_mb)==null?void 0:s.toFixed(2)," MB)"]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-3",style:{color:"var(--text-primary)"},children:"ZIP Package Includes:"}),e.jsxs("ul",{className:"space-y-2.5",children:[e.jsxs("li",{className:"flex items-center gap-2 text-xs font-medium",style:{color:"var(--text-muted)"},children:[e.jsx(z,{className:"w-4 h-4 text-emerald-500 shrink-0"})," Trained Model Checkpoint Weights (`models/best.pt`)"]}),p.map(m=>{var b;return e.jsxs("li",{className:"flex items-center gap-2 text-xs font-medium",style:{color:"var(--text-muted)"},children:[e.jsx(z,{className:"w-4 h-4 text-emerald-500 shrink-0"})," ",(b=c.find(N=>N.id===m))==null?void 0:b.name," exported format"]},m)}),e.jsxs("li",{className:"flex items-center gap-2 text-xs font-medium",style:{color:"var(--text-muted)"},children:[e.jsx(z,{className:"w-4 h-4 text-emerald-500 shrink-0"})," Python Inference Script (`inference.py`)"]}),e.jsxs("li",{className:"flex items-center gap-2 text-xs font-medium",style:{color:"var(--text-muted)"},children:[e.jsx(z,{className:"w-4 h-4 text-emerald-500 shrink-0"})," FastAPI REST Server (`app.py`)"]}),e.jsxs("li",{className:"flex items-center gap-2 text-xs font-medium",style:{color:"var(--text-muted)"},children:[e.jsx(z,{className:"w-4 h-4 text-emerald-500 shrink-0"})," `requirements.txt` & `README.md` Setup Instructions"]})]})]}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:S,className:"w-full py-3.5 rounded-xl font-bold flex items-center justify-center gap-2 border-2 border-emerald-500 text-emerald-500 hover:bg-emerald-500 hover:text-white transition-all shadow-lg shadow-emerald-500/10",children:[e.jsx(le,{className:"w-5 h-5"}),"Download Model ZIP Archive"]})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center opacity-50",children:[e.jsx(X,{className:"w-16 h-16 mb-4 text-slate-400"}),e.jsx("p",{className:"text-sm font-medium",style:{color:"var(--text-primary)"},children:'Click "Generate Model ZIP Package" to prepare downloadable code & model'})]})]})})]})},fs=()=>{const{isDark:t}=Y(),r=W(),[h,u]=k.useState(""),[p,C]=k.useState("my_models"),[T,x]=k.useState([]),[M,o]=k.useState(!1);k.useEffect(()=>{i()},[]);const i=async()=>{o(!0);try{const l=await R.get("/api/v1/cv/models");l.data.models&&x(l.data.models)}catch{x([{id:"m1",name:"YOLOv8s Helmet Detection",task:"object_detection",mAP50:.942,size_mb:22.5,tag:"Trained",completed_at:"2026-07-27"},{id:"m2",name:"ResNet50 Brain Tumor Classifier",task:"classification",mAP50:.985,size_mb:98.1,tag:"High Acc",completed_at:"2026-07-26"}])}finally{o(!1)}},g=async l=>{var v;try{await R.post(`/api/v1/cv/models/${l}/export`,{formats:["pytorch","onnx"]});const s=await R.get(`/api/v1/cv/export/${l}/download`,{responseType:"blob"}),m=window.URL.createObjectURL(new Blob([s.data])),b=document.createElement("a");b.href=m,b.setAttribute("download",`model_${l}.zip`),document.body.appendChild(b),b.click(),(v=b.parentNode)==null||v.removeChild(b),r.success("Model downloaded successfully!")}catch{r.error("Failed to download model.")}},w=l=>{window.confirm("Are you sure you want to delete this trained model?")&&(x(v=>v.filter(s=>s.id!==l)),r.success("Model deleted from hub."))},c=[{id:"my_models",label:"My Models"},{id:"community",label:"Community"},{id:"pretrained",label:"Pre-trained SOTA"}],S=p==="my_models"?T:p==="community"?[{name:"Medical Mask Detect",task:"Object Detection",mAP50:.89,size_mb:45,author:"Dr. Jane Smith",downloads:"12K"},{name:"Retail Shelf Scanner",task:"Object Detection",mAP50:.91,size_mb:60,author:"RetailCorp",downloads:"8K"},{name:"Plant Disease Seg",task:"Segmentation",mAP50:.85,size_mb:110,author:"AgriTech Labs",downloads:"5K"}]:[{name:"YOLOv11x",task:"Object Detection",mAP50:.985,size_mb:180,isVerified:!0,downloads:"1.2M",tag:"SOTA"},{name:"SAM 2 (Large)",task:"Zero-Shot Segmentation",mAP50:.99,size_mb:350,isVerified:!0,downloads:"850K",tag:"Meta AI"},{name:"Florence-2",task:"Vision-Language",mAP50:.96,size_mb:420,isVerified:!0,downloads:"500K",tag:"Microsoft"},{name:"YOLO-World",task:"Open-Vocabulary Detection",mAP50:.94,size_mb:220,isVerified:!0,downloads:"410K",tag:"Real-time"},{name:"RT-DETR",task:"Object Detection",mAP50:.95,size_mb:140,isVerified:!0,downloads:"320K",tag:"Transformer"}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 relative max-w-xl",children:[e.jsx(ke,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4",style:{color:"var(--text-muted)"}}),e.jsx("input",{type:"text",placeholder:"Search models by name, architecture, or task...",value:h,onChange:l=>u(l.target.value),className:"w-full pl-10 pr-4 py-2.5 rounded-xl border focus:ring-2 focus:ring-emerald-500/50 outline-none transition-all",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)",color:"var(--text-primary)"}})]}),e.jsx("div",{className:"flex p-1 rounded-xl bg-black/5 dark:bg-white/5 border w-fit",style:{borderColor:"var(--border-color)"},children:c.map(l=>e.jsx("button",{onClick:()=>C(l.id),className:`px-4 py-2 rounded-lg text-sm font-medium transition-all ${p===l.id?"bg-white dark:bg-slate-800 shadow-sm text-emerald-500":"hover:bg-black/5 dark:hover:bg-white/5 text-slate-500 dark:text-slate-400"}`,children:l.label},l.id))})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:S.length===0&&!M?e.jsx("div",{className:"col-span-full py-12 text-center text-slate-500",children:"No models found."}):S.map((l,v)=>{var s,m,b,N,_;return e.jsxs("div",{className:"p-5 rounded-2xl border flex flex-col transition-all hover:-translate-y-1 hover:border-emerald-500/50 hover:shadow-xl hover:shadow-emerald-500/10 group relative overflow-hidden",style:{backgroundColor:"var(--bg-card)",borderColor:"var(--border-color)"},children:[l.tag&&e.jsx("div",{className:"absolute top-0 right-0 px-3 py-1 bg-emerald-500 text-white text-[10px] font-bold tracking-wider uppercase rounded-bl-xl",children:l.tag}),e.jsxs("div",{className:"flex justify-between items-start mb-4 mt-2",children:[e.jsxs("div",{className:"flex-1 min-w-0 pr-2",children:[e.jsxs("h3",{className:"font-bold text-lg truncate flex items-center gap-1.5",style:{color:"var(--text-primary)"},children:[l.name||((m=(s=l.config)==null?void 0:s.model)==null?void 0:m.toUpperCase())||"Unknown Model",l.isVerified&&e.jsx(Re,{className:"w-4 h-4 text-blue-500 shrink-0"})]}),e.jsxs("div",{className:"text-xs font-mono mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"text-emerald-500",children:l.job_id?l.job_id.substring(0,8):l.author||"Official"}),l.downloads&&e.jsxs("span",{className:"text-slate-500",children:["• ",l.downloads," dl"]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 opacity-0 group-hover:opacity-100 transition-all",children:[e.jsx("button",{onClick:()=>g(l.id),className:"p-2 rounded-xl border bg-emerald-500/10 hover:bg-emerald-500 hover:text-white transition-all text-emerald-500",title:"Download Model (.zip)",style:{borderColor:"var(--border-color)"},children:e.jsx(le,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>w(l.id),className:"p-2 rounded-xl border border-red-500/20 bg-red-500/10 hover:bg-red-500 hover:text-white transition-all text-red-500",title:"Delete Model",children:e.jsx(Ce,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"flex items-center gap-2 mb-5 text-xs font-medium",children:e.jsx("span",{className:"px-2.5 py-1 rounded-md bg-black/5 dark:bg-white/5 border border-black/5 dark:border-white/5",style:{color:"var(--text-primary)"},children:l.task||((b=l.config)==null?void 0:b.task)||"object_detection"})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-5",children:[e.jsxs("div",{className:"p-3 rounded-xl border bg-gradient-to-br from-emerald-500/5 to-transparent flex flex-col items-center justify-center text-center transition-colors group-hover:border-emerald-500/20",style:{borderColor:"var(--border-color)"},children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider font-bold mb-1",style:{color:"var(--text-muted)"},children:"mAP50 Score"}),e.jsxs("div",{className:"font-bold text-lg text-emerald-500 font-mono",children:[((((N=l.metrics)==null?void 0:N.mAP50)||l.mAP50||0)*100).toFixed(1),"%"]})]}),e.jsxs("div",{className:"p-3 rounded-xl border bg-black/5 dark:bg-white/5 flex flex-col items-center justify-center text-center transition-colors group-hover:border-slate-500/20",style:{borderColor:"var(--border-color)"},children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider font-bold mb-1",style:{color:"var(--text-muted)"},children:"Model Size"}),e.jsxs("div",{className:"font-bold text-lg font-mono",style:{color:"var(--text-primary)"},children:[((_=l.metrics)==null?void 0:_.modelSizeMB)||l.size_mb||"?"," MB"]})]})]}),e.jsxs("div",{className:"mt-auto pt-4 border-t flex items-center justify-between text-xs font-medium",style:{borderColor:"var(--border-color)",color:"var(--text-muted)"},children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(es,{className:"w-3.5 h-3.5"})," ",new Date(l.completed_at||Date.now()).toLocaleDateString()]}),e.jsxs("span",{className:"flex items-center gap-1 text-amber-500 bg-amber-500/10 px-2 py-0.5 rounded-full",children:[e.jsx(ds,{className:"w-3 h-3 fill-amber-500"})," 4.9"]})]})]},v)})})]})},Gs=()=>{var F,E;const{isDark:t}=Y(),r=W(),{activeTab:h,setActiveTab:u,datasets:p,setDatasets:C,addDataset:T,activeDatasetId:x,setActiveDatasetId:M,activeJobId:o,setActiveJobId:i,trainingJobs:g,addTrainingJob:w,updateTrainingJob:c}=G();k.useRef(null);const j=t?"bg-[#0a0b10]":"bg-slate-50",d=t?"bg-white/[0.03]":"bg-white",S=t?"border-white/[0.06]":"border-slate-200",l=t?"text-white":"text-slate-900",v=t?"text-slate-400":"text-slate-600",s="text-slate-500";k.useEffect(()=>{m()},[]),k.useEffect(()=>{let a=null;const n=g.find($=>$.id===o);return n&&(n.status==="running"||n.status==="starting")&&(a=new EventSource(`${R.defaults.baseURL||""}/api/v1/cv/train/${o}/progress`),a.onmessage=$=>{try{const P=JSON.parse($.data);if(P.error){a==null||a.close();return}o&&c(o,{status:P.status,progress:P.progress,metrics:P.metrics,modelPath:P.model_path,completedAt:P.completed_at}),["completed","failed","cancelled"].includes(P.status)&&(a==null||a.close(),P.status==="completed"?(r.success("Training completed!"),u("results")):P.status==="failed"&&r.error("Training failed."))}catch{}},a.onerror=()=>{a==null||a.close()}),()=>{a&&a.close()}},[o]);const m=async()=>{try{const a=await R.get("/api/v1/cv/datasets");a.data.datasets&&(C(a.data.datasets),a.data.datasets.length>0&&!x&&M(a.data.datasets[0].id))}catch(a){console.error("Failed to fetch datasets",a)}},[b,N]=k.useState(null),_=a=>{T(a),M(a.id),a.taskType&&N(a.taskType),u("vision_tasks")},I=async(a,n,$)=>{var P,Z;if(x)try{const H=p.find(q=>q.id===x),ie=$||b||(H==null?void 0:H.taskType)||"classification",ue=await R.post("/api/v1/cv/train",{dataset_id:x,mode:a,config:n,task_type:ie});if(ue.data.success){const q=ue.data.job_id;w({id:q,datasetId:x,userId:"current",mode:a,config:n,status:"starting",progress:{status:"starting",epoch:0,totalEpochs:n.epochs,loss:0,valLoss:0,metrics:{},logs:[`Initializing ${a.toUpperCase()} training job for task: ${ie.toUpperCase()}...`],systemStats:{gpuUsage:0,vramUsage:"0GB",cpuUsage:0,ramUsage:"0GB"},startedAt:new Date().toISOString()},startedAt:new Date().toISOString()}),i(q),u("live_training"),r.success(`Started ${a} training for ${ie.replace(/_/g," ")}`)}}catch(H){r.error(((Z=(P=H.response)==null?void 0:P.data)==null?void 0:Z.detail)||"Failed to start training")}},y=async()=>{if(o)try{await R.post(`/api/v1/cv/train/${o}/stop`),r.success("Training stopped")}catch{}},D=async()=>{if(o)try{await R.post(`/api/v1/cv/train/${o}/pause`)}catch{}},L=async()=>{if(o)try{await R.post(`/api/v1/cv/train/${o}/resume`)}catch{}},O=g.filter(a=>a.status==="completed"),B=k.useMemo(()=>O.length===0?null:O.reduce((a,n)=>{var $,P;return((($=n.metrics)==null?void 0:$.mAP50)||0)>(((P=a.metrics)==null?void 0:P.mAP50)||0)?n:a},O[0]),[O]),f=[{id:"overview",label:"Overview",icon:Ee},{id:"data",label:"Dataset",icon:K},{id:"vision_tasks",label:"Vision Tasks",icon:de},{id:"training",label:"Training",icon:ne},{id:"live_training",label:"Live Training",icon:se},{id:"results",label:"Results",icon:ve},{id:"prediction",label:"Prediction",icon:$e},{id:"experiments",label:"Experiments",icon:Fe},{id:"model_hub",label:"Model Hub",icon:ss},{id:"deploy",label:"Deploy & Export",icon:ts}],A=g.find(a=>a.id===o);return e.jsxs("div",{className:`flex flex-col h-full overflow-hidden ${j}`,children:[e.jsxs("div",{className:`flex items-center justify-between p-4 border-b shrink-0 z-10 ${d} ${S}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-br from-emerald-500 to-teal-600 text-white shadow-lg shadow-emerald-500/20",children:e.jsx(Q,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:`text-lg font-bold ${l}`,children:"Computer Vision Studio"}),e.jsx("p",{className:`text-xs ${v}`,children:"Zero-code, end-to-end vision AI pipelines"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[x&&e.jsxs("div",{className:`hidden md:flex items-center gap-2 px-3 py-1.5 rounded-lg border text-xs font-medium ${S} ${t?"bg-white/[0.03]":"bg-slate-50"}`,children:[e.jsx(K,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("span",{className:`truncate max-w-[140px] ${l}`,children:((F=p.find(a=>a.id===x))==null?void 0:F.name)||"Unknown"})]}),O.length>0&&e.jsxs("div",{className:`hidden md:flex items-center gap-2 px-3 py-1.5 rounded-lg border text-xs font-medium ${S} ${t?"bg-emerald-500/10":"bg-emerald-50"}`,children:[e.jsx(z,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:[O.length," trained"]})]})]})]}),e.jsx("div",{className:"flex flex-1 overflow-hidden",children:e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx("div",{className:`flex border-b overflow-x-auto no-scrollbar ${S} ${d}`,children:f.map(a=>e.jsxs("button",{onClick:()=>u(a.id),className:`flex items-center gap-2 px-5 py-3.5 font-medium text-xs transition-all border-b-2 whitespace-nowrap ${h===a.id?"border-emerald-500 text-emerald-500":`border-transparent ${v} hover:text-emerald-400`}`,children:[e.jsx(a.icon,{className:"w-3.5 h-3.5"}),a.label,a.id==="live_training"&&(A==null?void 0:A.status)==="running"&&e.jsx("div",{className:"ml-1 w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"})]},a.id))}),e.jsx("div",{className:"p-4 md:p-6 lg:p-8",children:e.jsx(we,{mode:"wait",children:e.jsxs(U.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.2},className:"max-w-7xl mx-auto",children:[h==="overview"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:`p-5 rounded-2xl border ${d} ${S} transition-all hover:border-emerald-500/30`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${t?"bg-blue-500/10":"bg-blue-50"}`,children:e.jsx(K,{className:"w-4 h-4 text-blue-500"})}),e.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${s}`,children:"Datasets"})]}),e.jsx("p",{className:`text-3xl font-extrabold ${l}`,children:p.length}),e.jsxs("p",{className:`text-xs ${v} mt-1`,children:[p.reduce((a,n)=>a+n.numImages,0)," total images"]})]}),e.jsxs("div",{className:`p-5 rounded-2xl border ${d} ${S} transition-all hover:border-emerald-500/30`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${t?"bg-emerald-500/10":"bg-emerald-50"}`,children:e.jsx(z,{className:"w-4 h-4 text-emerald-500"})}),e.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${s}`,children:"Models"})]}),e.jsx("p",{className:`text-3xl font-extrabold ${l}`,children:O.length}),e.jsxs("p",{className:`text-xs ${v} mt-1`,children:[g.filter(a=>a.status==="running").length," training now"]})]}),e.jsxs("div",{className:`p-5 rounded-2xl border ${d} ${S} transition-all hover:border-emerald-500/30`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${t?"bg-purple-500/10":"bg-purple-50"}`,children:e.jsx(ae,{className:"w-4 h-4 text-purple-500"})}),e.jsx("span",{className:`text-[10px] font-bold uppercase tracking-wider ${s}`,children:"Best mAP50"})]}),e.jsx("p",{className:`text-3xl font-extrabold ${l}`,children:B?`${((((E=B.metrics)==null?void 0:E.mAP50)||0)*100).toFixed(1)}%`:"—"}),e.jsx("p",{className:`text-xs ${v} mt-1`,children:B?B.config.model.toUpperCase():"No models yet"})]}),e.jsxs("div",{className:"p-5 rounded-2xl border bg-gradient-to-br from-emerald-500 to-teal-600 text-white shadow-lg shadow-emerald-500/20 cursor-pointer hover:shadow-xl hover:scale-[1.02] transition-all",onClick:()=>u("data"),children:[e.jsx(te,{className:"w-7 h-7 mb-3 opacity-80"}),e.jsx("p",{className:"font-bold text-base",children:"New Project"}),e.jsx("p",{className:"text-xs opacity-80 mt-0.5",children:"Upload Dataset"})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[{icon:de,title:"Object Detection",desc:"YOLOv8 · RT-DETR · YOLO-World",badge:"Most Popular",onClick:()=>u("vision_tasks")},{icon:J,title:"Image Classification",desc:"ResNet · EfficientNet · ViT",badge:"Fast Training",onClick:()=>u("vision_tasks")},{icon:ye,title:"Instance Segmentation",desc:"YOLO-Seg · Mask R-CNN · SAM 2",badge:"Pixel-Perfect",onClick:()=>u("vision_tasks")}].map((a,n)=>e.jsxs("button",{onClick:a.onClick,className:`p-5 rounded-2xl border text-left transition-all hover:-translate-y-1 hover:shadow-lg group ${d} ${S} hover:border-emerald-500/40`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:`p-2 rounded-xl ${t?"bg-emerald-500/10":"bg-emerald-50"} group-hover:bg-emerald-500/20 transition-colors`,children:e.jsx(a.icon,{className:"w-5 h-5 text-emerald-500"})}),e.jsx("span",{className:"text-[9px] font-bold px-2 py-0.5 rounded bg-emerald-500/10 text-emerald-500 tracking-wider",children:a.badge})]}),e.jsx("h3",{className:`text-sm font-bold ${l} group-hover:text-emerald-500 transition-colors`,children:a.title}),e.jsx("p",{className:`text-xs ${v} mt-0.5`,children:a.desc})]},n))}),e.jsxs("div",{className:`p-6 rounded-2xl border ${d} ${S}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:`text-sm font-bold ${l}`,children:"Recent Datasets"}),e.jsx("button",{onClick:()=>u("data"),className:"text-xs font-medium text-emerald-500 hover:text-emerald-400",children:"View All →"})]}),p.length===0?e.jsx("div",{className:`text-center py-8 ${s} text-sm`,children:"No datasets uploaded yet. Upload your first dataset to get started."}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:p.slice(0,6).map(a=>e.jsxs("div",{onClick:()=>{M(a.id),u("data")},className:`p-4 rounded-xl border cursor-pointer transition-all hover:border-emerald-500/40 hover:-translate-y-0.5 ${S} ${t?"hover:bg-white/[0.02]":"hover:bg-slate-50"} ${x===a.id?"border-emerald-500/50 ring-1 ring-emerald-500/20":""}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1.5 truncate ${l}`,children:a.name}),e.jsxs("div",{className:`text-xs flex gap-3 ${v}`,children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(J,{className:"w-3 h-3"})," ",a.numImages," imgs"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ae,{className:"w-3 h-3"})," ",a.numClasses," cls"]})]})]},a.id))})]}),g.length>0&&e.jsxs("div",{className:`p-6 rounded-2xl border ${d} ${S}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:`text-sm font-bold ${l}`,children:"Training History"}),e.jsx("button",{onClick:()=>u("experiments"),className:"text-xs font-medium text-emerald-500 hover:text-emerald-400",children:"All Experiments →"})]}),e.jsx("div",{className:"space-y-2",children:g.slice(0,5).map(a=>{var n;return e.jsxs("div",{className:`flex items-center justify-between p-3 rounded-xl border ${S} ${t?"hover:bg-white/[0.02]":"hover:bg-slate-50"} transition-colors`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${a.status==="completed"?"bg-emerald-500":a.status==="running"?"bg-blue-500 animate-pulse":a.status==="failed"?"bg-red-500":"bg-slate-400"}`}),e.jsxs("div",{children:[e.jsx("span",{className:`text-xs font-bold ${l}`,children:a.config.model.toUpperCase()}),e.jsxs("span",{className:`text-xs ${s} ml-2`,children:[a.mode," · ",a.progress.totalEpochs," epochs"]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[((n=a.metrics)==null?void 0:n.mAP50)&&e.jsxs("span",{className:"text-xs font-bold text-emerald-500 font-mono",children:["mAP: ",(a.metrics.mAP50*100).toFixed(1),"%"]}),e.jsx("span",{className:`text-[10px] font-bold px-2 py-0.5 rounded-full uppercase tracking-wider ${a.status==="completed"?"bg-emerald-500/10 text-emerald-500":a.status==="running"?"bg-blue-500/10 text-blue-500":a.status==="failed"?"bg-red-500/10 text-red-500":"bg-slate-500/10 text-slate-500"}`,children:a.status})]})]},a.id)})})]})]}),h==="data"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(cs,{onUploadComplete:_}),e.jsx(ms,{})]}),h==="vision_tasks"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:"p-2 rounded-xl bg-emerald-500/10",children:e.jsx(ze,{className:"w-5 h-5 text-emerald-500"})}),e.jsxs("div",{children:[e.jsx("h2",{className:`text-lg font-bold ${l}`,children:"Vision Tasks"}),e.jsx("p",{className:`text-xs ${v}`,children:"Auto-detected from your dataset. Override if needed."})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[{type:"object_detection",icon:de,title:"Object Detection",desc:"Find and locate multiple objects using bounding boxes.",format:"YOLO, COCO",models:"YOLOv8, RT-DETR"},{type:"classification",icon:J,title:"Image Classification",desc:"Categorize images into predefined classes.",format:"Folder Structure",models:"ResNet, EfficientNet"},{type:["semantic_segmentation","instance_segmentation"],icon:ye,title:"Instance Segmentation",desc:"Pixel-perfect masks for object boundaries.",format:"YOLO, COCO",models:"YOLO-Seg, Mask R-CNN"},{type:"pose_estimation",icon:se,title:"Keypoint Detection",desc:"Detect and track specific points on objects.",format:"COCO Keypoints",models:"YOLO-Pose, HRNet"},{type:"ocr",icon:Te,title:"OCR",desc:"Extract text from images.",format:"JSON/TXT",models:"TrOCR, PaddleOCR"}].map((a,n)=>{var Z;const $=(Z=p.find(H=>H.id===x))==null?void 0:Z.taskType,P=Array.isArray(a.type)?a.type.includes($||""):$===a.type;return e.jsxs("div",{className:`p-5 rounded-2xl border transition-all cursor-pointer relative overflow-hidden ${d} ${P?"border-emerald-500 shadow-lg shadow-emerald-500/10":`${S} hover:border-emerald-500/40 hover:-translate-y-0.5`}`,children:[P&&e.jsx("div",{className:"absolute top-0 right-0 px-2.5 py-0.5 bg-emerald-500 text-white text-[9px] font-bold rounded-bl-lg tracking-wider",children:"AUTO-DETECTED"}),e.jsx(a.icon,{className:`w-8 h-8 mb-3 ${P?"text-emerald-500":v}`}),e.jsx("h3",{className:`text-sm font-bold mb-1.5 ${l}`,children:a.title}),e.jsx("p",{className:`text-xs ${v} mb-3 leading-relaxed`,children:a.desc}),e.jsxs("div",{className:`space-y-1.5 text-xs ${v} mb-4`,children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:s,children:"Format:"}),e.jsx("span",{className:"text-emerald-500 font-medium",children:a.format})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:s,children:"Models:"}),e.jsx("span",{className:`font-medium ${l}`,children:a.models})]})]}),e.jsx("button",{onClick:()=>{const H=Array.isArray(a.type)?a.type[0]:a.type;N(H),u("training"),r.info(`Selected task: ${a.title}`)},className:`w-full py-2 rounded-xl text-sm font-bold transition-colors ${P?"bg-emerald-500 text-white hover:bg-emerald-600":`border ${S} text-emerald-500 hover:bg-emerald-500 hover:text-white`}`,children:"Proceed to Training"})]},n)})})]}),h==="training"&&e.jsx(xs,{onStartTraining:I,selectedTaskType:b||void 0,disabled:!x||A&&A.status==="running"}),h==="live_training"&&(A?e.jsx(hs,{job:A,onPause:D,onResume:L,onStop:y}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(Me,{className:`w-14 h-14 mb-4 ${t?"text-slate-700":"text-slate-300"}`}),e.jsx("h3",{className:`text-lg font-bold ${l}`,children:"No Active Training"}),e.jsx("p",{className:`text-xs ${v} mt-1`,children:"Start a training job to monitor it live."}),e.jsx("button",{onClick:()=>u("training"),className:"mt-4 px-5 py-2 rounded-xl bg-emerald-500 text-white font-medium text-sm hover:bg-emerald-400 transition-colors",children:"Go to Training Config"})]})),h==="results"&&((A==null?void 0:A.status)==="completed"?e.jsx(ps,{job:A}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(ve,{className:`w-14 h-14 mb-4 ${t?"text-slate-700":"text-slate-300"}`}),e.jsx("h3",{className:`text-lg font-bold ${l}`,children:"No Results Yet"}),e.jsx("p",{className:`text-xs ${v} mt-1`,children:"Complete a training job to view results."})]})),h==="prediction"&&e.jsx(bs,{}),h==="experiments"&&e.jsx(us,{}),h==="model_hub"&&e.jsx(fs,{}),h==="deploy"&&e.jsx(gs,{})]},h)})})]})})]})};export{Gs as default}; | |