import{at as z,j as e,L as I,q as j,bU as T,u as C,ed as Q,c2 as ee,c7 as B,d as k,c1 as se,r as u,ba as F,gP as te,bq as oe,cy as ne,x as y,ge as S,cU as A,cP as re,aJ as _,ck as O,aL as N,f as L,lo as ie,c5 as Y,bW as ae,jC as le,jp as ce,cb as de,O as me,fI as pe,gN as ue,ao as R,v as V,b4 as he,lp as xe,bB as ge,aP as je,l7 as fe,fH as ve,lq as ye,lr as we,ke as be,ls as Ce,lt as Me,lu as De,lv as ke,lw as Se,lx as Ee,l9 as Le,ly as Ie,jW as Te,A as G,dR as Ne,lz as _e,lA as Oe,h as Pe,F as q,c8 as $e,iU as Ae,gF as J,gs as Re,w as Ve,cn as Be,bJ as Fe,c as U,by as Ge,gS as Ue,cY as H,t as He}from"./index-Cox3ZWL0.js";import{A as We,g as M}from"./defineProperty-Bl0iR0r2.js";import{C as D}from"./CardBoundary-uDlhZsJD.js";import{M as Ke}from"./ModelSchema-iwKOxrpT.js";import{b as ze,e as Qe,d as Z,f as Ye}from"./index-DlTLF62i.js";import{T as qe,P as Je}from"./Tags-BeTNHmPZ.js";import{a as Ze}from"./utils-ihHlm9yU.js";import{g as Xe,b as es,a as ss}from"./getDefaultFormValues-vy9JWs45.js";import{P as ts}from"./Panel-Cu-mlmB5.js";import"./index-Bk4_24eg.js";import"./utils-aVdaNBWM.js";import"./types-Cay-L1a6.js";import"./transform-C2GfmqNu.js";import"./string-cKWu9XK9.js";import"./zoom-D5h43YeK.js";import"./bump-BmRQ39WQ.js";import"./Deprecated-g8R65bmH.js";import"./TagsForm-ChKTdobu.js";import"./useUpdateTdOrFvInfoService-aQ3jOLSd.js";import"./index-uwkRD1BL.js";import"./randomArrayString---X8tfjV.js";import"./sort-BOLIcXtz.js";import"./TagsEdit-CcZdnM9s.js";const os=s=>`import hopsworks

# connect with Hopsworks
project = hopsworks.login()

# get Hopsworks Model Registry
mr = project.get_model_registry()

# get model object
model = mr.get_model("${s.modelName}", version=${s.modelVersion})
`,ns=s=>{if(!s.metrics)return"";const n=Object.keys(s.metrics);return`EVALUATION_METRIC="${n.shift()}"  ${n.length?`# or ${n.join(", ")}`:""}
SORT_METRICS_BY="max" # your sorting criteria

# get best model based on custom metrics
best_model = mr.get_best_model("${s.modelName}",
                               EVALUATION_METRIC,
                               SORT_METRICS_BY)
`},rs=s=>`# get the model you want to download
model = mr.get_model("${s.modelName}", version=${s.modelVersion})

# download artifact files
model.download()
`,is=s=>`from hsml.schema import Schema
from hsml.model_schema import ModelSchema

SAVED_MODEL_PATH = "path-to-the-new-model-files"

x_df = [] # your training data (Pandas, numpy, tensors,...)
y_df = [] # your labels

input_schema = Schema(x_df)
output_schema = Schema(y_df)

# create the model metadata for a python model (or tensorflow, sklearn, torch...)
model = mr.python.create_model("${s.modelName}", 
                               metrics={EVALUATION_METRIC: EVALUATION_METRIC_VALUE},
                               input_example=x_df,
                               model_schema=ModelSchema(input_schema=input_schema,
                                                        output_schema=output_schema))

# save model version in the Model Registry
model.save(SAVED_MODEL_PATH)
`,as=({model:s})=>{const{isLoading:n,project:a}=z();if(n||!a)return e.jsx(I,{});const t={projectName:a==null?void 0:a.projectName,modelName:s.name,modelVersion:s.version,metrics:s.metrics},d=e.jsx(T,{copyButton:!0,title:"Download model",content:rs(t),language:"py"});return e.jsxs(j,{alignItems:"flex-start",sx:{gap:"20px"},p:"20px",children:[e.jsxs(j,{flexDirection:"column",sx:{gap:"20px"},width:"50%",children:[e.jsx(T,{copyButton:!0,title:"Get model",content:os(t),language:"py"}),s.metrics&&Object.keys(s.metrics).length>0?e.jsx(T,{copyButton:!0,title:"Get best model based on custom metrics",content:ns(t),language:"py"}):d]}),e.jsxs(j,{flexDirection:"column",sx:{gap:"20px"},width:"50%",children:[e.jsx(T,{copyButton:!0,title:"Train a new version of the model",content:is(t),language:"py"}),s.metrics&&d]})]})},ls=()=>{const{id:s,vId:n,mId:a}=C(),{data:t=[],isLoading:d}=ze({modelId:`${a}_${n}`,projectId:s});return e.jsx(qe,{isLoading:d,type:Q.modelVersion,data:t})},W={overflow:"auto",padding:0},cs=({label:s,date:n,primary:a,...t})=>{const{DATE_TIME_FULL:d}=ee.DATE_TIME;return e.jsxs(j,{flexDirection:"column",...t,children:[e.jsx(B,{mb:"3px",gray:!0,children:s}),e.jsx(k,{primary:a,children:se(n,d)})]})},ds=({data:s})=>{const{mId:n,vId:a}=C(),t=F(),{data:d,isLoading:l}=te(),{data:p,isLoading:c}=oe(),{isServiceUser:r}=ne(),o=u.useCallback(()=>{t(y.project.settings.fileBrowserWithPath,{"*":`Models/${n}/${a}/Files`})},[n,a,t]),i=u.useCallback(()=>{if(s!=null&&s.framework)switch(s==null?void 0:s.framework){case"TENSORFLOW":return S.TENSORFLOW;case"SKLEARN":return S.SKLEARN;default:return S.PYTHON}return S.PYTHON},[s==null?void 0:s.framework]),m=u.useCallback(()=>{if(s!=null&&s.framework){if(s.framework===S.TENSORFLOW)return S.TENSORFLOW;if(s.framework===A.VLLM)return A.VLLM}return A.PYTHON},[s.framework]),h=u.useCallback(()=>{const{kafkaTopic:x,inferenceLogging:f,modelInput:v,predictions:w}=Xe(c,r),b=ss(l,r,d);t(y.project.deployments.create,void 0,{state:{modelFramework:i(),modelServer:m(),kserve:es(l,r,d),modelName:n,modelVersion:+a,kafkaTopicDTO:x,inferenceLogging:f,modelInput:v,predictions:w,requestedInstances:b}})},[t,i,m,n,a,l,r,d,c]);return e.jsxs(j,{children:[e.jsx(re,{firstName:s.userFullName.split(" ")[0],lastName:s.userFullName.split(" ")[1]}),e.jsx(cs,{ml:"25px",label:"Version created on",date:s.created}),e.jsxs(j,{flexDirection:"column",ml:"30px",flex:"1",children:[e.jsx(B,{mb:"3px",gray:!0,children:"Framework"}),e.jsx(k,{children:s!=null&&s.framework?s.framework:"No framework"})]}),e.jsxs(j,{children:[e.jsx(_,{intent:"secondary",onClick:o,mr:"8px",children:"Browse model files ->"}),e.jsx(_,{onClick:h,children:"Deploy this version ->"})]})]})},ms=u.memo(ds),ps=({metrics:s})=>e.jsx(j,{flexWrap:"wrap",gap:"20px",children:s?Object.entries(s).map(([n,a])=>e.jsxs(j,{flexDirection:"column",children:[e.jsx(B,{mb:"3px",gray:!0,children:n}),e.jsx(k,{color:"black",children:a})]},n)):e.jsx(O,{children:"No metrics found for this version"})}),us=u.memo(ps),hs=()=>{var m,h,x,f,v,w;const{id:s,mId:n,vId:a}=C(),{currentData:t,isLoading:d}=N({id:+s,path:`Models/${n}/README.md`}),{currentData:l,isLoading:p}=N({id:+s,path:`Models/${n}/${a}/README.md`}),{currentData:c,isLoading:r}=N({id:+s,path:`Models/${n}/${a}/Files/README.md`}),o=c||l||t,i=r||p||d;return e.jsxs(L,{title:"Model card",actions:e.jsx(xs,{data:(m=o==null?void 0:o.preview)==null?void 0:m.content,dataForAllVersions:(h=l==null?void 0:l.preview)==null?void 0:h.content}),maxHeight:"400px",expandable:(x=o==null?void 0:o.preview)!=null&&x.content?((f=o==null?void 0:o.preview)==null?void 0:f.content.length)>400:!1,mb:(v=o==null?void 0:o.preview)!=null&&v.content&&((w=o==null?void 0:o.preview)==null?void 0:w.content.length)>400?"20px":"0px",children:[i&&e.jsx(I,{}),o?e.jsx(ie,{content:o.preview.content||(l==null?void 0:l.preview.content)||"",...o}):e.jsx(Y,{mainText:"No README.md"})]})},xs=({data:s,dataForAllVersions:n})=>{const a=ae(),{id:t,mId:d,vId:l}=C(),{project:p}=z(),[c,r]=u.useState(void 0),o=!!c,i=u.useCallback(()=>r(void 0),[]),[m,h]=u.useState(""),[x,f]=u.useState(!1),[v]=le();u.useEffect(()=>{h(c==="all-versions"?n:s)},[s,n,c]);const w=u.useCallback(async()=>{const b=c==="all-versions"?`Models/${d}`:`Models/${d}/${l}/Files`,E=`${b}/README.md`;f(!0),(c==="all-versions"?n:s)!==void 0&&await v({id:+t,path:E});const g=new Blob([m??""],{type:""}),$=`/Projects/${p.projectName}/${b}`;await ce({file:g,uploadPath:$,options:{},projectId:t,name:"README.md"}),a(de.invalidateTags([{id:E,type:me.ProjectTags.FileContent}])),f(!1),i()},[m,s,n,v,a,c,t,d,p,i,l]);return e.jsxs(e.Fragment,{children:[e.jsxs(pe,{variant:"outline",spacing:"0.5",children:[e.jsx(_,{onClick:()=>r("this-version"),children:s!==void 0?"Edit":"Create"}),e.jsx(ue,{sx:{mt:"0px",height:"36px",span:{height:"100%"},":hover":{">button":{div:{bg:"primaryShade1"}}}},items:[{value:"Edit for all model versions",onClick:()=>r("all-versions")}],renderButton:({isOpen:b})=>e.jsx(R,{icon:V.arrow_down,color:"white",height:"100%",alignItems:"center",sx:{bg:b?"primaryShade1":"primary"}})})]}),e.jsx(he,{size:"7xl",hasCloseButton:!0,isOpen:o,onClose:i,title:"Create README.md",closeOnBackdropClick:!1,closeOnEsc:!1,footer:e.jsx(ge,{onClick:w,isLoading:x,children:"Save"}),children:e.jsx(xe,{value:m,onChange:h,height:"calc(100vh - 200px)"})})]})},X=({name:s,path:n,onClick:a,minHeight:t=200,sx:d,withoutText:l=!1,maxWidth:p=400})=>{const{id:c}=C(),{currentData:r,isLoading:o}=N({id:+c,path:n}),i=je({fileName:s}),m=`data:image/${i};base64,${r==null?void 0:r.preview.content}`;return e.jsx(fe,{onClick:a,sx:d,children:e.jsxs(ve,{isLoaded:!o,minHeight:t,children:[i!=="svg"&&e.jsx(ye,{src:m,m:"auto"}),i==="svg"&&e.jsx(we,{content:(r==null?void 0:r.preview.content)??"",sx:{svg:{maxWidth:p,maxHeight:p}}}),!l&&e.jsx(O,{m:"8px",children:s})]})})},gs=({content:s,isOpen:n,onClose:a})=>{const[t,d]=u.useState(s.find(({name:o})=>o===n)),l=s.findIndex(({name:o})=>o===(t==null?void 0:t.name)),p=u.useCallback(o=>()=>{let i=l+o;i<0&&(i=s.length-1),i>=s.length&&(i=0),d(s[i])},[s,l]),c=p(1),r=p(-1);return be({ArrowLeft:r,ArrowRight:c}),u.useEffect(()=>{d(s.find(({name:o})=>o===n))},[s,n]),e.jsxs(Ce,{isOpen:!!n,onClose:a,isCentered:!0,size:"8xl",children:[e.jsx(Me,{}),e.jsxs(De,{height:"fit-content",children:[e.jsx(ke,{mb:"10px",children:t==null?void 0:t.name}),e.jsx(Se,{}),e.jsx(Ee,{p:"0",children:e.jsxs(Le,{gap:"10px",mb:"10px",justifyContent:"space-between",sx:{userSelect:"none"},children:[e.jsx(R,{size:"xl",icon:V.arrow_left,sx:K,color:"gray",onClick:r}),s.map(({name:o,path:i})=>{const m=s.findIndex(({name:x})=>x===o),h=()=>l===0?m===s.length-1?"left":"right":l===s.length-1?m===0?"right":"left":m>l?"right":"left";return e.jsx(Ie,{in:o===(t==null?void 0:t.name),direction:h(),style:{position:o===(t==null?void 0:t.name)?"relative":"fixed",left:o===(t==null?void 0:t.name)?0:"-10000px",top:o===(t==null?void 0:t.name)?0:"-1000000px",opacity:o===(t==null?void 0:t.name)?1:0,transition:"opacity 1.8s ease"},children:e.jsx(X,{name:o,path:i,withoutText:!0,sx:{opacity:(o===(t==null?void 0:t.name),1),transition:"all 1.5s ease"}})},o)}),e.jsx(R,{size:"xl",icon:V.arrow_right,sx:K,color:"gray",onClick:c})]})})]})]})},js=u.memo(gs),K={bg:"grayShade3",alignItems:"center",minWidth:"60px",justifyContent:"center",cursor:"pointer"},fs=5,vs=Ae(2,8),ys=()=>{const{id:s,mId:n,vId:a}=C(),[t,d]=u.useState(fs),[l,p]=u.useState(void 0),c=u.useCallback(()=>p(void 0),[]),{currentData:r,isLoading:o}=Te({id:+s,path:`Models/${n}/${a}/Files/images`,fallbackPath:`Models/${n}/${a}/images`,skipError:!0},{refetchOnFocus:!0,selectFromResult:G({currentData:G({items:Ne(i=>_e({fileName:i.attributes.name}))})})});return e.jsxs(L,{title:"Model evaluation images",actions:e.jsxs(j,{gap:"10px",alignItems:"center",children:[e.jsx(O,{children:"Max number of images"}),e.jsx($e,{placeholder:"",options:vs.map(i=>({key:i,label:i.toString()})),value:t,onChange:i=>d(i.key),maxListHeight:"300px"})]}),contentProps:{sx:{bg:"grayShade3"}},children:[o&&e.jsx(I,{}),e.jsx(Oe,{minChildWidth:`${1100/t}px`,spacing:"10px",children:Pe((r==null?void 0:r.items)??[])?e.jsx(Y,{mainText:"No evaluation images"}):((r==null?void 0:r.items)??[]).map(i=>e.jsx(q,{sx:{border:"1px solid",borderColor:"grayShade2",borderRadius:"2px"},children:e.jsx(X,{path:i.attributes.path,name:i.attributes.name,onClick:()=>{p(i.attributes.name)},sx:{cursor:"pointer"},maxWidth:1100/t})},i.attributes.id))}),e.jsx(js,{isOpen:l,onClose:c,content:(r==null?void 0:r.items.map(i=>({name:i.attributes.name,path:i.attributes.path})))??[]})]})},ws=({children:s,...n})=>{const{id:a,mId:t,vId:d}=C(),l=F(),{currentData:{items:p}={items:[]}}=Qe({projectId:a,modelName:t}),{currentData:c,isLoading:r}=Z({projectId:a,modelName:t,modelVersion:+d}),{isLoading:o,data:i}=J({projectId:a,model:t}),m=u.useMemo(()=>(p==null?void 0:p.map(x=>({id:Number(x.version),version:Number(x.version),deployments:((i==null?void 0:i.all)??[]).filter(f=>f.modelVersion===x.version).length})))??[],[i,p]),h=x=>{l(y.project.models.versionView,{vId:Number.parseInt(x,10),mId:(c==null?void 0:c.name)||""})};return r||o||!c?e.jsx(I,{}):e.jsx(ts,{type:Q.modelVersion,data:c,title:c.name,version:c.version,versions:m,onVersionChange:h,idColor:"labels.blueShade1",...n,children:s})},Ws=()=>{var E,P;const{id:s,mId:n,vId:a}=C(),t=F(),{handleDelete:d}=u.useContext(Re),[l,p]=Ve(!1),{isObserver:c}=Be(),{currentData:r,isLoading:o}=Z({projectId:s,modelName:n,modelVersion:+a}),{isLoading:i,data:m}=J({projectId:s,model:n}),h=u.useMemo(()=>((m==null?void 0:m.all)??[]).filter(g=>g.modelVersion===+a).sort(Ze),[m==null?void 0:m.all,a]),x=(g,$)=>()=>{t(y.project.deployments.overview,{dId:$,mId:g})},f=()=>{t(y.project.models.overview,{mId:n})},[v,{isLoading:w}]=Ye(),b=async()=>{try{const g=`${n}_${a}`;await v({projectId:s,mlId:g}).unwrap(),d(He(y.project.models.versionView,y.project.value,{id:s,mId:n,vId:a})),t(y.project.models.list)}catch(g){console.error(g)}};return o||i||!r?e.jsx(I,{}):e.jsxs(e.Fragment,{children:[e.jsx(Fe,{title:`Delete ${n} v${a}`,secondaryText:"Once you delete a model, there is no going back. Please be certain.",isOpen:l,onClose:p,mainButtonProps:{children:"Delete",onClick:b,isLoading:w,"data-test":"delete-model"},secondaryButtonProps:{children:"Back",onClick:p}}),e.jsx(ws,{showDelete:!c,onClickDelete:p,children:e.jsx(_,{intent:"secondary",onClick:f,ml:"10px",children:e.jsx(U,{bold:!0,children:"all versions ->"})})}),e.jsx(q,{mt:"10px",width:"100%",children:e.jsx(ms,{data:r})}),e.jsxs(j,{mt:"20px",width:"100%",flexWrap:"wrap",sx:{gap:"8px"},children:[e.jsx(k,{sx:{flex:"1 1 100%"},children:r.description?e.jsx(O,{my:"20px",children:(r==null?void 0:r.description)||"-"}):e.jsx(U,{my:"20px",gray:!0,children:"-"})}),e.jsx(k,{sx:{flex:"1 1 100%"},children:h.length>0?e.jsxs(k,{children:["This version is used in ",e.jsx(k,{primary:!0,display:"inline",children:h.length}),Ge(" deployment",h.length)]}):"This version is not used in any deployments"}),e.jsx(j,{sx:{gap:"6px"},children:h.map(g=>e.jsx(Ue,{height:"31px",isActive:g.status===H.RUNNING,indicator:"horizontal",mode:g.status===H.RUNNING?"highlight":"default",onClick:x(r.name,g.id),children:`${g.name} ->`},g.id))})]}),e.jsx(j,{flexDirection:"column",sx:{gap:"20px"},py:"20px",children:e.jsxs(We,{children:[e.jsx(M,{name:"modelMetrics",children:e.jsx(D,{children:e.jsx(L,{title:"Model metrics",maxHeight:"400px",children:e.jsx(us,{metrics:r.metrics})})})}),e.jsx(M,{name:"modelEvaluation",children:e.jsx(D,{children:e.jsx(ys,{})})}),e.jsx(M,{name:"modelCard",children:e.jsx(D,{children:e.jsx(hs,{})})}),e.jsx(M,{name:"modelSchema",children:e.jsx(D,{children:e.jsx(L,{title:"Model schema",contentProps:W,children:e.jsx(Ke,{schema:(P=(E=r.modelSchema)==null?void 0:E.preview)==null?void 0:P.content})})})}),e.jsx(M,{name:y.overviewAnchors.provenance,children:e.jsx(D,{title:"Provenance",children:e.jsx(Je,{projectId:+s,artifact:r})})}),e.jsx(M,{name:"modelTags",children:e.jsx(D,{children:e.jsx(ls,{})})}),e.jsx(M,{name:"codeSnippets",children:e.jsx(D,{children:e.jsx(L,{title:"Code snippets",contentProps:W,children:e.jsx(as,{model:r})})})})]})})]})};export{Ws as default};
