mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-21 17:05:22 +03:00
feat: add experimentalAltTextGeneration flag
This commit is contained in:
parent
83bcf82f0e
commit
7c26cece3e
2 changed files with 17 additions and 3 deletions
|
@ -23,6 +23,8 @@ const description = ref(props.attachment.description ?? '')
|
||||||
|
|
||||||
const generationInProgress = ref(false)
|
const generationInProgress = ref(false)
|
||||||
|
|
||||||
|
const userSettings = useUserSettings()
|
||||||
|
|
||||||
async function generateAltText() {
|
async function generateAltText() {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(JSON.parse(JSON.stringify(props)))
|
console.log(JSON.parse(JSON.stringify(props)))
|
||||||
|
@ -35,7 +37,18 @@ async function generateAltText() {
|
||||||
if (generationInProgress.value)
|
if (generationInProgress.value)
|
||||||
return
|
return
|
||||||
|
|
||||||
// TODO @Shinigami92 2024-05-27: Show confirm dialog warning message that a model with ~250MiB will be downloaded
|
const experimentalAltTextGeneration = getPreferences(userSettings.value, 'experimentalAltTextGeneration')
|
||||||
|
|
||||||
|
if (!experimentalAltTextGeneration) {
|
||||||
|
// TODO @Shinigami92 2024-05-28: Use a fancy dialog instead of the browser's alert
|
||||||
|
// eslint-disable-next-line no-alert
|
||||||
|
const allow = confirm('This will download a model with ~250MiB. Do you want to continue? This is an experimental feature and might fail in several scenarios.')
|
||||||
|
|
||||||
|
if (!allow)
|
||||||
|
return
|
||||||
|
|
||||||
|
togglePreferences('experimentalAltTextGeneration')
|
||||||
|
}
|
||||||
|
|
||||||
generationInProgress.value = true
|
generationInProgress.value = true
|
||||||
|
|
||||||
|
@ -44,11 +57,10 @@ async function generateAltText() {
|
||||||
|
|
||||||
const pipe = await pipeline('image-to-text', 'Xenova/vit-gpt2-image-captioning')
|
const pipe = await pipeline('image-to-text', 'Xenova/vit-gpt2-image-captioning')
|
||||||
|
|
||||||
// const imageElement = document.querySelector<HTMLImageElement>('.dialog-main img.status-attachment-image')!
|
|
||||||
const imageElement = new Image()
|
const imageElement = new Image()
|
||||||
|
// See https://www.hacksoft.io/blog/handle-images-cors-error-in-chrome for why using `?request-with-cors`
|
||||||
imageElement.crossOrigin = 'Anonymous'
|
imageElement.crossOrigin = 'Anonymous'
|
||||||
imageElement.src = `${url}?request-with-cors`
|
imageElement.src = `${url}?request-with-cors`
|
||||||
await imageElement.decode()
|
|
||||||
|
|
||||||
const dataUrl = new Promise<string>((resolve) => {
|
const dataUrl = new Promise<string>((resolve) => {
|
||||||
imageElement.onload = () => {
|
imageElement.onload = () => {
|
||||||
|
|
|
@ -32,6 +32,7 @@ export interface PreferencesSettings {
|
||||||
experimentalGitHubCards: boolean
|
experimentalGitHubCards: boolean
|
||||||
experimentalUserPicker: boolean
|
experimentalUserPicker: boolean
|
||||||
experimentalEmbeddedMedia: boolean
|
experimentalEmbeddedMedia: boolean
|
||||||
|
experimentalAltTextGeneration: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserSettings {
|
export interface UserSettings {
|
||||||
|
@ -88,6 +89,7 @@ export const DEFAULT__PREFERENCES_SETTINGS: PreferencesSettings = {
|
||||||
experimentalGitHubCards: true,
|
experimentalGitHubCards: true,
|
||||||
experimentalUserPicker: true,
|
experimentalUserPicker: true,
|
||||||
experimentalEmbeddedMedia: false,
|
experimentalEmbeddedMedia: false,
|
||||||
|
experimentalAltTextGeneration: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultUserSettings(locales: string[]): UserSettings {
|
export function getDefaultUserSettings(locales: string[]): UserSettings {
|
||||||
|
|
Loading…
Reference in a new issue