[pycharm] PY-63670 updates in the HF community module for HF model choice MVP

GitOrigin-RevId: 598962bb98a7435320cd224ca9c8fcdcabe897fd
This commit is contained in:
Bogdan Kirilenko
2024-03-27 21:01:08 +00:00
committed by intellij-monorepo-bot
parent 6e67ff4544
commit 0646bef0d4
4 changed files with 22 additions and 18 deletions
@@ -7,7 +7,7 @@ python.hugging.face.base.url=https://huggingface.co
python.hugging.face.updated.suffix= Updated {0}
python.hugging.face.open.on.link.text=Open on Hugging Face
python.hugging.face.placeholder.gated.model=<font color='gray'>Sorry, this {0} is gated.<br>Please visit the [HuggingFace website]({1}) <br>for more details about the {2} card.</font>
python.hugging.face.placeholder.gated.model=Sorry, this {0} is gated.<br>Please visit the [HuggingFace website]({1}) <br>for more details about the {2} card.
python.hugging.face.placeholder.no.readme=This model has no description available. For more details, please follow the [link]({0})
python.hugging.face.placeholder.trimmed=*Please find the rest of the {0} card [here]({1})*
python.hugging.face.placeholder.no.internet=Failed to fetch data for {0}. Please check your internet connection.
@@ -5,9 +5,8 @@ import org.jetbrains.annotations.ApiStatus
@ApiStatus.Internal
enum class HuggingFaceModelSortKey(val value: String, val displayName: String) {
AUTHOR("author", "Author"),
CREATED_AT("createdAt", "Created At"),
LAST_MODIFIED("lastModified", "Last Modified"),
DOWNLOADS("downloads", "Downloads"),
LIKES("likes", "Likes");
LIKES("likes", "Likes"),
CREATED_AT("createdAt", "Created At"),
LAST_MODIFIED("lastModified", "Last Modified");
}
@@ -37,6 +37,12 @@ abstract class HuggingFaceCache(private val maxSize: Int) : PersistentStateCompo
}
}
@Synchronized
fun saveEntity(entityData: HuggingFaceEntityBasicApiData) {
cacheMap[entityData.itemId] = entityData
nameSet.add(entityData.itemId)
}
@Synchronized
fun isInCache(entityId: String): Boolean {
if (hotCache.containsKey(entityId)) return true
@@ -67,7 +73,6 @@ abstract class HuggingFaceCache(private val maxSize: Int) : PersistentStateCompo
}
}
@State(
name = "HuggingFaceModelsCache",
storages = [Storage("huggingFaceModelsCache.xml")]
@@ -11,6 +11,7 @@ import com.intellij.python.community.impl.huggingFace.HuggingFaceEntityKind
import com.intellij.python.community.impl.huggingFace.api.HuggingFaceEntityBasicApiData
import com.intellij.python.community.impl.huggingFace.api.HuggingFaceURLProvider
import com.intellij.python.community.impl.huggingFace.service.PyHuggingFaceBundle
import com.jetbrains.python.PythonLanguage
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.Nls
@@ -29,7 +30,7 @@ class HuggingFaceHtmlBuilder(
} else {
generateCardHeader(modelDataApiContent)
}
@NlsSafe val convertedHtml = readAction { DocMarkdownToHtmlConverter.convert(project, modelCardContent) }
@NlsSafe val convertedHtml = readAction { DocMarkdownToHtmlConverter.convert(project, modelCardContent, PythonLanguage.INSTANCE) }
val wrappedBodyContent = HtmlChunk.div()
.setClass(DocumentationMarkup.CLASS_CONTENT)
@@ -58,8 +59,6 @@ class HuggingFaceHtmlBuilder(
listOf(HtmlChunk.text(PyHuggingFaceBundle.message("python.hugging.face.dataset")), HtmlChunk.nbsp(2))
}
val modelInfoRow = DocumentationMarkup.GRAYED_ELEMENT
.children(
*conditionalChunks.toTypedArray(),
@@ -80,21 +79,22 @@ class HuggingFaceHtmlBuilder(
.child(HtmlChunk.text(PyHuggingFaceBundle.getMessage("python.hugging.face.open.on.link.text")))
.wrapWith("p")
val headerContainer = HtmlChunk.div()
.setClass(DocumentationMarkup.CLASS_DEFINITION)
.children(
modelNameWithIconRow,
modelInfoRow,
linkRow,
)
val headerContainer = HtmlChunk.div()
.setClass(DocumentationMarkup.CLASS_DEFINITION)
.children(
modelNameWithIconRow,
modelInfoRow,
linkRow,
)
return headerContainer
}
companion object {
private const val NBHP = "&#8209;"
private val DOWNLOADS_ICON = HtmlChunk.tag("icon")
.attr("src", "AllIcons.Actions.Download")
.attr("src", "AllIcons.Plugins.Downloads")
private val LIKES_ICON = HtmlChunk.tag("icon")
.attr(".src", "AllIcons.Toolwindows.ToolWindowFavorites")
.attr(".src", "AllIcons.Plugins.Rating")
}
}