import{aw as W,j as e,D as I,$ as j,cM as N,u as w,ee as z,bP as ee,bU as B,f as D,bO as se,r as h,b9 as F,fk as te,bh as oe,ck as ne,q as y,fm as S,cI as P,cB as re,b1 as _,c6 as O,a_ as T,b as L,k7 as ie,bS as Y,bH as ae,ie as le,hV as ce,bZ as de,Q as me,jX as pe,fN as he,ap as A,C as R,aV as ue,k8 as xe,br as ge,b5 as je,k9 as fe,gV as ve,ka as ye,kb as be,iQ as ke,kc as we,kd as Me,ke as Ce,kf as De,kg as Se,kh as Ee,ki as Le,kj as Ie,iC as Ne,w as G,dw as Te,kk as _e,kl as Oe,h as $e,L as q,bV as Ve,hR as Pe,fF as X,fB as Ae,y as Re,c9 as Be,bz as Fe,c as H,bp as Ge,gQ as He,cL as U,o as Ue}from"./index-46ma1THH.js";import{A as Ke,a as M}from"./Anchor-VqM1KJ3L.js";import{C}from"./CardBoundary-BvnXl_ii.js";import{M as Qe}from"./ModelSchema-CBj5qNKE.js";import{b as We,e as ze,d as Z,f as Ye}from"./index-D241LvV7.js";import{S as qe,P as Xe}from"./SchematisedTags-CzFM4cV4.js";import{a as Ze}from"./utils-KrO_n7VT.js";import{g as Je,b as es,a as ss}from"./getDefaultFormValues-3rRlpL1j.js";import{P as ts}from"./Panel-CnxQ3Lqy.js";import"./index-DBUSvgea.js";import"./transform-DZgNhtp2.js";import"./string-CFFdVFMV.js";import"./zoom-A7rKCg-F.js";import"./bump-BmRQ39WQ.js";import"./Deprecated-CcWZugSq.js";import"./SchematisedTagsEdit-Yw_kmyod.js";import"./SchematisedTagsForm-dh4vAE2D.js";import"./useUpdateTdOrFvInfoService-BiDORrPs.js";import"./schematised-tags.selectors-WK3AUml0.js";import"./randomArrayString---X8tfjV.js";import"./sort-BOLIcXtz.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 the model artifact
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}=W();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(N,{copyButton:!0,title:"Download model",content:rs(t),language:"python"});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(N,{copyButton:!0,title:"Get model",content:os(t),language:"python"}),s.metrics&&Object.keys(s.metrics).length>0?e.jsx(N,{copyButton:!0,title:"Get best model based on custom metrics",content:ns(t),language:"python"}):d]}),e.jsxs(j,{flexDirection:"column",sx:{gap:"20px"},width:"50%",children:[e.jsx(N,{copyButton:!0,title:"Train a new version of the model",content:is(t),language:"python"}),s.metrics&&d]})]})},ls=()=>{const{id:s,vId:n,mId:a}=w(),{data:t=[],isLoading:d}=We({modelId:`${a}_${n}`,projectId:s});return e.jsx(qe,{isLoading:d,type:z.modelVersion,data:t})},K={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(D,{primary:a,children:se(n,d)})]})},ds=({data:s})=>{const{mId:n,vId:a}=w(),t=F(),{data:d,isLoading:l}=te(),{data:p,isLoading:c}=oe(),{isServiceUser:r}=ne(),o=h.useCallback(()=>{t(y.project.settings.fileBrowserWithPath,{"*":`Models/${n}/${a}/Files`})},[n,a,t]),i=h.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=h.useCallback(()=>{if(s!=null&&s.framework){if(s.framework===S.TENSORFLOW)return S.TENSORFLOW;if(s.framework===P.VLLM)return P.VLLM}return P.PYTHON},[s.framework]),u=h.useCallback(()=>{const{kafkaTopic:x,inferenceLogging:f,modelInput:v,predictions:b}=Je(c,r),k=es(l,r,d);t(y.project.deployments.create,void 0,{state:{modelFramework:i(),modelServer:m(),kserve:ss(l,r,d),modelName:n,modelVersion:+a,kafkaTopicDTO:x,inferenceLogging:f,modelInput:v,predictions:b,requestedInstances:k}})},[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(D,{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:u,children:"Deploy this version ->"})]})]})},ms=h.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(D,{color:"black",children:a})]},n)):e.jsx(O,{children:"No metrics found for this version"})}),hs=h.memo(ps),us=()=>{var m,u,x,f,v,b;const{id:s,mId:n,vId:a}=w(),{currentData:t,isLoading:d}=T({id:+s,path:`Models/${n}/README.md`}),{currentData:l,isLoading:p}=T({id:+s,path:`Models/${n}/${a}/README.md`}),{currentData:c,isLoading:r}=T({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:(u=l==null?void 0:l.preview)==null?void 0:u.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&&((b=o==null?void 0:o.preview)==null?void 0:b.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}=w(),{project:p}=W(),[c,r]=h.useState(void 0),o=!!c,i=h.useCallback(()=>r(void 0),[]),[m,u]=h.useState(""),[x,f]=h.useState(!1),[v]=le();h.useEffect(()=>{u(c==="all-versions"?n:s)},[s,n,c]);const b=h.useCallback(async()=>{const k=c==="all-versions"?`Models/${d}`:`Models/${d}/${l}/Files`,E=`${k}/README.md`;f(!0),(c==="all-versions"?n:s)!==void 0&&await v({id:+t,path:E});const g=new Blob([m??""],{type:""}),V=`/Projects/${p.projectName}/${k}`;await ce({file:g,uploadPath:V,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(he,{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:k})=>e.jsx(A,{icon:R.arrow_down,color:"white",height:"100%",alignItems:"center",sx:{bg:k?"primaryShade1":"primary"}})})]}),e.jsx(ue,{size:"7xl",hasCloseButton:!0,isOpen:o,onClose:i,title:"Create README.md",closeOnBackdropClick:!1,closeOnEsc:!1,footer:e.jsx(ge,{onClick:b,isLoading:x,children:"Save"}),children:e.jsx(xe,{value:m,onChange:u,height:"calc(100vh - 200px)"})})]})},J=({name:s,path:n,onClick:a,minHeight:t=200,sx:d,withoutText:l=!1,maxWidth:p=400})=>{const{id:c}=w(),{currentData:r,isLoading:o}=T({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(be,{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]=h.useState(s.find(({name:o})=>o===n)),l=s.findIndex(({name:o})=>o===(t==null?void 0:t.name)),p=h.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 ke({ArrowLeft:r,ArrowRight:c}),h.useEffect(()=>{d(s.find(({name:o})=>o===n))},[s,n]),e.jsxs(we,{isOpen:!!n,onClose:a,isCentered:!0,size:"8xl",children:[e.jsx(Me,{}),e.jsxs(Ce,{height:"fit-content",children:[e.jsx(De,{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(A,{size:"xl",icon:R.arrow_left,sx:Q,color:"gray",onClick:r}),s.map(({name:o,path:i})=>{const m=s.findIndex(({name:x})=>x===o),u=()=>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:u(),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(J,{name:o,path:i,withoutText:!0,sx:{opacity:(o===(t==null?void 0:t.name),1),transition:"all 1.5s ease"}})},o)}),e.jsx(A,{size:"xl",icon:R.arrow_right,sx:Q,color:"gray",onClick:c})]})})]})]})},js=h.memo(gs),Q={bg:"grayShade3",alignItems:"center",minWidth:"60px",justifyContent:"center",cursor:"pointer"},fs=5,vs=Pe(2,8),ys=()=>{const{id:s,mId:n,vId:a}=w(),[t,d]=h.useState(fs),[l,p]=h.useState(void 0),c=h.useCallback(()=>p(void 0),[]),{currentData:r,isLoading:o}=Ne({id:+s,path:`Models/${n}/${a}/Files/images`,fallbackPath:`Models/${n}/${a}/images`,skipError:!0},{refetchOnFocus:!0,selectFromResult:G({currentData:G({items:Te(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(Ve,{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:$e((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(J,{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})))??[]})]})},bs=({children:s,...n})=>{const{id:a,mId:t,vId:d}=w(),l=F(),{currentData:{items:p}={items:[]}}=ze({projectId:a,modelName:t}),{currentData:c,isLoading:r}=Z({projectId:a,modelName:t,modelVersion:+d}),{isLoading:o,data:i}=X({projectId:a,model:t}),m=h.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]),u=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:z.modelVersion,data:c,title:c.name,version:c.version,versions:m,onVersionChange:u,idColor:"labels.blueShade1",...n,children:s})},Hs=()=>{var E,$;const{id:s,mId:n,vId:a}=w(),t=F(),{handleDelete:d}=h.useContext(Ae),[l,p]=Re(!1),{isObserver:c}=Be(),{currentData:r,isLoading:o}=Z({projectId:s,modelName:n,modelVersion:+a}),{isLoading:i,data:m}=X({projectId:s,model:n}),u=h.useMemo(()=>((m==null?void 0:m.all)??[]).filter(g=>g.modelVersion===+a).sort(Ze),[m==null?void 0:m.all,a]),x=(g,V)=>()=>{t(y.project.deployments.overview,{dId:V,mId:g})},f=()=>{t(y.project.models.overview,{mId:n})},[v,{isLoading:b}]=Ye(),k=async()=>{try{const g=`${n}_${a}`;await v({projectId:s,mlId:g}).unwrap(),d(Ue(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:k,isLoading:b,"data-test":"delete-model"},secondaryButtonProps:{children:"Back",onClick:p}}),e.jsx(bs,{showDelete:!c,onClickDelete:p,children:e.jsx(_,{intent:"secondary",onClick:f,ml:"10px",children:e.jsx(H,{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(D,{sx:{flex:"1 1 100%"},children:r.description?e.jsx(O,{my:"20px",children:(r==null?void 0:r.description)||"-"}):e.jsx(H,{my:"20px",gray:!0,children:"-"})}),e.jsx(D,{sx:{flex:"1 1 100%"},children:u.length>0?e.jsxs(D,{children:["This version is used in ",e.jsx(D,{primary:!0,display:"inline",children:u.length}),Ge(" deployment",u.length)]}):"This version is not used in any deployments"}),e.jsx(j,{sx:{gap:"6px"},children:u.map(g=>e.jsx(He,{height:"31px",isActive:g.status===U.RUNNING,indicator:"horizontal",mode:g.status===U.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(Ke,{children:[e.jsx(M,{name:"modelMetrics",children:e.jsx(C,{children:e.jsx(L,{title:"Model metrics",maxHeight:"400px",children:e.jsx(hs,{metrics:r.metrics})})})}),e.jsx(M,{name:"modelEvaluation",children:e.jsx(C,{children:e.jsx(ys,{})})}),e.jsx(M,{name:"modelCard",children:e.jsx(C,{children:e.jsx(us,{})})}),e.jsx(M,{name:"modelSchema",children:e.jsx(C,{children:e.jsx(L,{title:"Model schema",contentProps:K,children:e.jsx(Qe,{schema:($=(E=r.modelSchema)==null?void 0:E.preview)==null?void 0:$.content})})})}),e.jsx(M,{name:y.overviewAnchors.provenance,children:e.jsx(C,{title:"Provenance",children:e.jsx(Xe,{projectId:+s,artifact:r})})}),e.jsx(M,{name:"modelTags",children:e.jsx(C,{children:e.jsx(ls,{})})}),e.jsx(M,{name:"codeSnippets",children:e.jsx(C,{children:e.jsx(L,{title:"Code snippets",contentProps:K,children:e.jsx(as,{model:r})})})})]})})]})};export{Hs as default};
