cli/pkg/lab/collector/huggingface.go
Claude 5e9a9c2790 feat: integrate lab dashboard as core lab serve
Port the standalone lab dashboard (lab.lthn.io) into the core CLI as
pkg/lab/ with collectors, handlers, and HTML templates. The dashboard
monitors machines, Docker containers, Forgejo, HuggingFace models,
training runs, and InfluxDB metrics with SSE live updates.

New command: core lab serve --bind :8080

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 05:53:52 +00:00

55 lines
1.2 KiB
Go

package collector
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
"forge.lthn.ai/core/cli/pkg/lab"
)
type HuggingFace struct {
author string
store *lab.Store
}
func NewHuggingFace(author string, s *lab.Store) *HuggingFace {
return &HuggingFace{author: author, store: s}
}
func (h *HuggingFace) Name() string { return "huggingface" }
func (h *HuggingFace) Collect(ctx context.Context) error {
u := fmt.Sprintf("https://huggingface.co/api/models?author=%s&sort=downloads&direction=-1&limit=20", h.author)
req, err := http.NewRequestWithContext(ctx, "GET", u, nil)
if err != nil {
return err
}
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
h.store.SetError("huggingface", err)
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err := fmt.Errorf("HuggingFace API returned %d", resp.StatusCode)
h.store.SetError("huggingface", err)
return err
}
var models []lab.HFModel
if err := json.NewDecoder(resp.Body).Decode(&models); err != nil {
h.store.SetError("huggingface", err)
return err
}
h.store.SetModels(models)
h.store.SetError("huggingface", nil)
return nil
}