{{ $id := delimit (slice "huggingface" (partial "functions/uid.html" .)) "-" }} {{- $model := .Get "model" -}} {{- $dataset := .Get "dataset" -}} {{- $hfAPI := "" -}} {{- $repoLink := "" -}} {{- $type := "" -}} {{- if $model -}} {{- $hfAPI = print "https://huggingface.co/api/models/" $model -}} {{- $repoLink = print "https://huggingface.co/" $model -}} {{- $type = "model" -}} {{- else if $dataset -}} {{- $hfAPI = print "https://huggingface.co/api/datasets/" $dataset -}} {{- $repoLink = print "https://huggingface.co/datasets/" $dataset -}} {{- $type = "dataset" -}} {{- end -}} {{- $huggingfaceData := dict -}} {{- with try (resources.GetRemote $hfAPI) -}} {{- with .Err -}} {{- warnf "huggingface shortcode: failed to fetch remote resource from %q: %s" $hfAPI $.Position -}} {{- else with .Value -}} {{- $huggingfaceData = . | transform.Unmarshal -}} {{- else -}} {{- warnf "huggingface shortcode: unable to get remote resource from %q: %s" $hfAPI $.Position -}} {{- end -}} {{- end -}} {{- with $huggingfaceData -}}
{{ template "HuggingFaceSVG" . }}
{{ .id | markdownify }}
{{- if .description -}}
{{ .description | replaceRE `Dataset Card for .+\s+Dataset Summary\s+` "" }}
{{- end -}}
{{ if eq $type "model" }} {{ if .pipeline_tag }}{{ .pipeline_tag }}{{ else }}model{{ end }} {{ else }} {{ if .task_categories }}{{ index .task_categories 0 }}{{ else }}dataset{{ end }} {{ end }}
{{ partial "icon.html" "heart-empty" }}
{{ if .likes }}{{ .likes }}{{ else }}0{{ end }}
{{ partial "icon.html" "download" }}
{{ if .downloads }}{{ .downloads }}{{ else }}0{{ end }}
{{ $fetchRepo := resources.Get "js/fetch-repo.js" }} {{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint (site.Params.fingerprintAlgorithm | default "sha512") }}
{{- else -}} {{ warnf "huggingface shortcode: unable to fetch %q: %s" $hfAPI .Position }} {{- end -}} {{ define "HuggingFaceSVG" }} {{/* prettier-ignore-start */}} {{/* prettier-ignore-end */}} {{ end }}