mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Implement the new alt text flow (bug 1909604)
For the Firefox pdf viewer, we want to use AI to guess an alt-text when adding an image to a pdf. For now the telemtry stuff is not implemented and will come soon. In order to test it locally: - set enableAltText, enableFakeMLManager and enableUpdatedAddImage to true. or in Firefox: - set browser.ml.enable, pdfjs.enableAltText and pdfjs.enableUpdatedAddImage to true.
This commit is contained in:
parent
8378c40f4c
commit
ed22d934e5
22 changed files with 1366 additions and 91 deletions
|
@ -56,9 +56,47 @@ class MLManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
async guess() {
|
||||
isReady(_name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
guess(_data) {}
|
||||
|
||||
toggleService(_name, _enabled) {}
|
||||
|
||||
static getFakeMLManager(options) {
|
||||
return new FakeMLManager(options);
|
||||
}
|
||||
}
|
||||
|
||||
class FakeMLManager {
|
||||
constructor({ enableGuessAltText }) {
|
||||
this.enableGuessAltText = enableGuessAltText;
|
||||
}
|
||||
|
||||
async isEnabledFor(_name) {
|
||||
return this.enableGuessAltText;
|
||||
}
|
||||
|
||||
async deleteModel(_service) {
|
||||
return null;
|
||||
}
|
||||
|
||||
isReady(_name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
guess({ request: { data } }) {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(data ? { output: "Fake alt text" } : { error: true });
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
|
||||
toggleService(_name, enabled) {
|
||||
this.enableGuessAltText = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
export { ExternalServices, initCom, MLManager, Preferences };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue