Spaces:
Running
Running
File size: 1,629 Bytes
d411f8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import API from './API'
class Descriptions {
private static instance: Descriptions | null = null
private descriptions: Record<string, any> = {}
private modelDescriptions: Record<string, any> = {}
private loaded: boolean = false
private loadingPromise: Promise<void> | null = null
private constructor() {}
static getInstance(): Descriptions {
if (!Descriptions.instance) {
Descriptions.instance = new Descriptions()
}
return Descriptions.instance
}
async load(): Promise<void> {
if (this.loaded) return
if (this.loadingPromise) return this.loadingPromise
this.loadingPromise = API.fetchDescriptions().then((data) => {
this.descriptions = data.descriptions || {}
this.modelDescriptions = data.model_descriptions || {}
this.loaded = true
})
return this.loadingPromise
}
getFullName(name: string): string | undefined {
return this.descriptions[name]?.full_name
}
getDescription(name: string): string | undefined {
return this.descriptions[name]?.description
}
getUrl(name: string): string | undefined {
return this.descriptions[name]?.link
}
getModelDescription(name: string): string | undefined {
return this.modelDescriptions[name]?.description
}
getModelFullName(name: string): string | undefined {
return this.modelDescriptions[name]?.full_name
}
getModelPaperUrl(name: string): string | undefined {
return this.modelDescriptions[name]?.paper_link
}
getModelGithubUrl(name: string): string | undefined {
return this.modelDescriptions[name]?.github_link
}
}
export default Descriptions
|