Merge pull request #6366 from menloresearch/fix/search-model-hub
fix: search hgf repo and downloaded filter
This commit is contained in:
commit
f886434c59
@ -194,46 +194,50 @@ function Hub() {
|
|||||||
fetchSources()
|
fetchSources()
|
||||||
}, [fetchSources])
|
}, [fetchSources])
|
||||||
|
|
||||||
|
const fetchHuggingFaceModel = async (searchValue: string) => {
|
||||||
|
if (
|
||||||
|
!searchValue.length ||
|
||||||
|
(!searchValue.includes('/') && !searchValue.startsWith('http'))
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsSearching(true)
|
||||||
|
if (addModelSourceTimeoutRef.current) {
|
||||||
|
clearTimeout(addModelSourceTimeoutRef.current)
|
||||||
|
}
|
||||||
|
|
||||||
|
addModelSourceTimeoutRef.current = setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
const repoInfo = await fetchHuggingFaceRepo(searchValue, huggingfaceToken)
|
||||||
|
if (repoInfo) {
|
||||||
|
const catalogModel = convertHfRepoToCatalogModel(repoInfo)
|
||||||
|
if (
|
||||||
|
!sources.some(
|
||||||
|
(s) =>
|
||||||
|
catalogModel.model_name.trim().split('/').pop() ===
|
||||||
|
s.model_name.trim() &&
|
||||||
|
catalogModel.developer.trim() === s.developer?.trim()
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
setHuggingFaceRepo(catalogModel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching repository info:', error)
|
||||||
|
} finally {
|
||||||
|
setIsSearching(false)
|
||||||
|
}
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
const handleSearchChange = (e: ChangeEvent<HTMLInputElement>) => {
|
const handleSearchChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
setIsSearching(false)
|
setIsSearching(false)
|
||||||
setSearchValue(e.target.value)
|
setSearchValue(e.target.value)
|
||||||
setHuggingFaceRepo(null) // Clear previous repo info
|
setHuggingFaceRepo(null) // Clear previous repo info
|
||||||
|
|
||||||
if (addModelSourceTimeoutRef.current) {
|
if (!showOnlyDownloaded) {
|
||||||
clearTimeout(addModelSourceTimeoutRef.current)
|
fetchHuggingFaceModel(e.target.value)
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
e.target.value.length &&
|
|
||||||
(e.target.value.includes('/') || e.target.value.startsWith('http'))
|
|
||||||
) {
|
|
||||||
setIsSearching(true)
|
|
||||||
|
|
||||||
addModelSourceTimeoutRef.current = setTimeout(async () => {
|
|
||||||
try {
|
|
||||||
// Fetch HuggingFace repository information
|
|
||||||
const repoInfo = await fetchHuggingFaceRepo(
|
|
||||||
e.target.value,
|
|
||||||
huggingfaceToken
|
|
||||||
)
|
|
||||||
if (repoInfo) {
|
|
||||||
const catalogModel = convertHfRepoToCatalogModel(repoInfo)
|
|
||||||
if (
|
|
||||||
!sources.some(
|
|
||||||
(s) =>
|
|
||||||
catalogModel.model_name.trim().split('/').pop() ===
|
|
||||||
s.model_name.trim()
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
setHuggingFaceRepo(catalogModel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching repository info:', error)
|
|
||||||
} finally {
|
|
||||||
setIsSearching(false)
|
|
||||||
}
|
|
||||||
}, 500)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,7 +512,15 @@ function Hub() {
|
|||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Switch
|
<Switch
|
||||||
checked={showOnlyDownloaded}
|
checked={showOnlyDownloaded}
|
||||||
onCheckedChange={setShowOnlyDownloaded}
|
onCheckedChange={(checked) => {
|
||||||
|
setShowOnlyDownloaded(checked)
|
||||||
|
if (checked) {
|
||||||
|
setHuggingFaceRepo(null)
|
||||||
|
} else {
|
||||||
|
// Re-trigger HuggingFace search when switching back to "All models"
|
||||||
|
fetchHuggingFaceModel(searchValue)
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<span className="text-xs text-main-view-fg/70 font-medium whitespace-nowrap">
|
<span className="text-xs text-main-view-fg/70 font-medium whitespace-nowrap">
|
||||||
{t('hub:downloaded')}
|
{t('hub:downloaded')}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user