Show a Hugging Face repository's model card on the mirror page
Opening a repository shows its model card, rendered from markdown, with its base model, license and languages above it; the listing names each repository's base model and license under its name. The card is a stranger's text: raw HTML and dangerous links are dropped, images are shown as links rather than loaded, and relative links point into the repository. Adds github.com/yuin/goldmark for the markdown. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
02fa639657
commit
3fea39feb9
10 files changed
+375
-27
No files matched your search
@@ -230,3 +230,39 @@ func TestExploringAsksForWhatThePageFilters(t *testing.T) {
|
||||
t.Errorf("the registry was asked %d times", calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestARepositoryCarriesItsCardWithoutTheHeader(t *testing.T) {
|
||||
c := registry(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case strings.HasPrefix(r.URL.Path, "/api/models/q/m/tree/"):
|
||||
_, _ = w.Write([]byte(`[{"type":"file","path":"README.md","size":40},{"type":"file","path":"m.gguf","size":1}]`))
|
||||
case r.URL.Path == "/api/models/q/m":
|
||||
_, _ = w.Write([]byte(`{"id":"q/m","sha":"abc","cardData":{"license":"apache-2.0","base_model":"Qwen/Qwen2.5-0.5B","language":["en","tr"]}}`))
|
||||
case r.URL.Path == "/q/m/raw/abc/README.md":
|
||||
_, _ = w.Write([]byte("---\nlicense: apache-2.0\n---\n\n# M\n\nA model.\n"))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
})
|
||||
got, err := c.Repo(t.Context(), "q/m")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Card != "# M\n\nA model." {
|
||||
t.Errorf("card = %q", got.Card)
|
||||
}
|
||||
if got.License != "apache-2.0" || len(got.BaseModel) != 1 || got.BaseModel[0] != "Qwen/Qwen2.5-0.5B" ||
|
||||
len(got.Languages) != 2 {
|
||||
t.Errorf("card header = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAListingNamesTheBaseModelAndLicenseFromItsTags(t *testing.T) {
|
||||
m := Model{Tags: []string{"gguf", "base_model:quantized:Qwen/Qwen3-8B", "base_model:Qwen/Qwen3-8B", "license:apache-2.0"}}
|
||||
if m.BaseModel() != "Qwen/Qwen3-8B" || m.License() != "apache-2.0" {
|
||||
t.Errorf("base %q, license %q", m.BaseModel(), m.License())
|
||||
}
|
||||
if (Model{Tags: []string{"base_model:org/x"}}).BaseModel() != "org/x" {
|
||||
t.Error("a base model with no relation should read as itself")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user