Skip to content

Commit

Permalink
fix: minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
debanjandhar12 committed Dec 11, 2023
1 parent 9a23cbd commit c2b181a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/templates/AnkiCardTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import template from "./template.html?raw";

function getTemplate() {
const templateModifiedBasedOnUserSetting = template;
console.log(logseq.settings.ankiFieldOptions);
if(!Array.isArray(logseq.settings.ankiFieldOptions)) return template;

let modifiedField = "{{cloze:Text}}";
Expand Down
13 changes: 9 additions & 4 deletions src/ui/customized/OcclusionEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,22 +421,27 @@ const OcclusionEditorComponent: React.FC<{
const [isAIGeneratingOcclusion, setIsAIGeneratingOcclusion] = useState(false);

const aiGenerateOcclusion = async () => {
let worker = null;
try {
setIsAIGeneratingOcclusion(true);
const worker = await createWorker("eng", 3, {});
worker = await createWorker("eng", 3, {});
await worker.setParameters({tessedit_pageseg_mode: PSM.SPARSE_TEXT});
const ret = await worker.recognize(imgEl.src);
let counter = 0;
if (!ret.data.confidence || ret.data.confidence < 50)
if (!ret.data.confidence || ret.data.confidence < 40)
throw new Error("AI failed to recognize the image");
console.log(ret);
for (const paragraph of _.get(ret, "data.paragraphs", [])) {
const width = paragraph.bbox.x1 - paragraph.bbox.x0;
const height = paragraph.bbox.y1 - paragraph.bbox.y0;

// Ignore low confidence paragraphs
if (paragraph.confidence < 40) continue;
// Ignore small occlusions
if (width < 4 || height < 4) continue;
if (width * height < Math.pow(0.025, 2) * imgEl.width * imgEl.height) continue;
// Ignore occlusions that intersect with existing ones

function doRectsCollide(a, b) {
return !(
a.top + a.height < b.top ||
Expand Down Expand Up @@ -486,11 +491,11 @@ const OcclusionEditorComponent: React.FC<{
if (counter === 0)
logseq.Editor.showMsg("All possible occlusions already present.", "warning");
else logseq.Editor.showMsg(`Generated ${counter} occlusions`, "success");
await worker.terminate();
setIsAIGeneratingOcclusion(false);
} catch (e) {
logseq.Editor.showMsg("Failed to generate occlusions", "error");
}
if (worker) await worker.terminate();
setIsAIGeneratingOcclusion(false);
};

return (
Expand Down

0 comments on commit c2b181a

Please sign in to comment.