Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Jun 11, 2024
1 parent 0f8b489 commit 7a4f5fd
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 1 deletion.
132 changes: 132 additions & 0 deletions .github/ci/modelslist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package main

import (
"fmt"
"html/template"
"io/ioutil"
"os"

"gopkg.in/yaml.v3"
)

var modelPageTemplate string = `
<!DOCTYPE html>
<html>
<head>
<title>LocalAI model gallery</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
</head>
<body>
<style>
.is-hidden {
display: none;
}
</style>
<div class="columns mx-1">
<div class="column is-half is-offset-one-quarter">
<section class="hero is-primary mb-4">
<div class="hero-body">
<p class="title">
LocalAI model gallery list
</p>
<p class="subtitle">
Here is a glimpse of the models you can find in LocalAI. To use the models, you can download them from the LocalAI app.
</p>
</div>
</section>
<section>
<div>
<label for="searchbox" class="is-size-5">Search</label>
<input class='input mb-5' type="search"
id="searchbox" placeholder="Live search keyword..">
</div>
{{ range $_, $model := .Models }}
<div class="box">
<strong>{{$model.Name}}</strong>
<img src="{{$model.Icon}}" alt="{{$model.Name}}" class="mb-3">
{{ range $_, $u := $model.URLs }}
<p>{{ $u }}</p>
{{ end }}
<p>{{ $model.Description }}</p>
<a href="http://localhost:8080/browse?term={{ $model.Name}}" class="button is-primary">Install in LocalAI ( instance at localhost:8080 )</a>
</div>
{{ end }}
</section>
</div>
</div>
<script>
let cards = document.querySelectorAll('.box')
function liveSearch() {
let search_query = document.getElementById("searchbox").value;
//Use innerText if all contents are visible
//Use textContent for including hidden elements
for (var i = 0; i < cards.length; i++) {
if(cards[i].textContent.toLowerCase()
.includes(search_query.toLowerCase())) {
cards[i].classList.remove("is-hidden");
} else {
cards[i].classList.add("is-hidden");
}
}
}
//A little delay
let typingTimer;
let typeInterval = 500;
let searchInput = document.getElementById('searchbox');
searchInput.addEventListener('keyup', () => {
clearTimeout(typingTimer);
typingTimer = setTimeout(liveSearch, typeInterval);
});
</script>
</body>
</html>
`

type GalleryModel struct {
Name string `json:"name" yaml:"name"`
URLs []string `json:"urls" yaml:"urls"`
Icon string `json:"icon" yaml:"icon"`
Description string `json:"description" yaml:"description"`
}

func main() {
// read the YAML file which contains the models

f, err := ioutil.ReadFile(os.Args[1])
if err != nil {
fmt.Println("Error reading file:", err)
return
}

models := []*GalleryModel{}
err = yaml.Unmarshal(f, &models)
if err != nil {
// write to stderr
os.Stderr.WriteString("Error unmarshaling YAML: " + err.Error() + "\n")
return
}

// render the template
data := struct {
Models []*GalleryModel
}{
Models: models,
}
tmpl := template.Must(template.New("modelPage").Parse(modelPageTemplate))

err = tmpl.Execute(os.Stdout, data)
if err != nil {
fmt.Println("Error executing template:", err)
return
}
}
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -836,4 +836,10 @@ swagger:

.PHONY: gen-assets
gen-assets:
$(GOCMD) run core/dependencies_manager/manager.go embedded/webui_static.yaml core/http/static/assets
$(GOCMD) run core/dependencies_manager/manager.go embedded/webui_static.yaml core/http/static/assets

docs/layouts/_default:
mkdir -p docs/layouts/_default

docs-models: docs/layouts/_default
$(GOCMD) run ./.github/ci/modelslist.go ./gallery/index.yaml > docs/layouts/_default/gallery.html
6 changes: 6 additions & 0 deletions docs/content/docs/gallery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

+++
title = "Gallery"
layout = "gallery"
url = '/gallery/'
+++

0 comments on commit 7a4f5fd

Please sign in to comment.