-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core…
… into gh-pages
- Loading branch information
Showing
19 changed files
with
437 additions
and
478 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Number of AST Nodes | ||
|
||
|
||
<script> | ||
import sloc from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm' | ||
|
||
function countNodes(srcCode) { | ||
let nodeCount = 0 | ||
srcCode.traverseAsAST({ | ||
enter(path) { | ||
nodeCount++; | ||
} | ||
}) | ||
return nodeCount | ||
} | ||
|
||
// const srcURL = lively4url + '/../active-expressions/src/'; | ||
// function skip(fileURL) { | ||
// return fileURL.endsWith('utils.js') | ||
// } | ||
// const srcURL = lively4url + '/../aexpr-ticking/src/'; | ||
// function skip(fileURL) { | ||
// return fileURL.endsWith('utils.js') | ||
// } | ||
const srcURL = lively4url + '/../aexpr-interpretation/src/'; | ||
function skip(fileURL) { | ||
return false && fileURL.includes('babelsberg') || fileURL.endsWith('utils.js') | ||
} | ||
// const srcURL = lively4url + '/../aexpr-source-transformation-propagation/src/'; | ||
// function skip(fileURL) { | ||
// return false | ||
// } | ||
// const srcURL = lively4url + '/../babel-plugin-aexpr-source-transformation/'; | ||
// function skip(fileURL) { | ||
// return !fileURL.endsWith('./index.js') | ||
// } | ||
const { contents: files } = await fetch(srcURL, { | ||
method: "OPTIONS", | ||
headers: {filelist: "true"} | ||
}).then(r => r.json()) | ||
|
||
// lively.files.visualizeFileTreeMap(srcURL) | ||
|
||
|
||
const metrics = [] | ||
for (let file of files) { | ||
const fileURL = srcURL + file.name; | ||
if (fileURL.endsWith('.js') && !skip(fileURL)) { | ||
const code = await fileURL.fetchText(); | ||
const numNodes = countNodes(code) | ||
const sLoc = sloc(code, 'js').source | ||
metrics.push([fileURL, `${numNodes} (${sLoc})`]) | ||
} | ||
} | ||
|
||
<table>{...metrics.map(([file, numNodes]) => <tr><td>{file}</td><td>{numNodes}</td></tr>)}</table> | ||
</script> |
69 changes: 69 additions & 0 deletions
69
demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/results.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Convention | ||
- ast nodes 136 = 18 + 118 | ||
- sloc (29) = (1) + (28) | ||
|
||
[aexpr-ticking](https://github.com/active-expressions/aexpr-ticking.git) | ||
e9b4034 | ||
e9b4034606dd286ac494f20293cf7e7e9649e0ac | ||
|
||
- https://lively-kernel.org/lively4/aexpr/../aexpr-ticking/src/./aexpr-ticking.js 18 (1) | ||
- https://lively-kernel.org/lively4/aexpr/../aexpr-ticking/src/./ticking/ticking-active-expressions.js 118 (28) | ||
|
||
# Interpretation | ||
- ast nodes 787 = 12+182+224+369 | ||
- sloc (170) = (1)+(43)+(51)+(75) | ||
|
||
[aexpr-interpretation](https://github.com/active-expressions/aexpr-interpretation.git) | ||
46d1d17 | ||
46d1d175b4cb040bda636fe871ef5d2f70f5e3e8 | ||
|
||
- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./aexpr-interpretation.js 12 (1) | ||
- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/property-accessor.js 182 (43) | ||
- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/listener.js 224 (51) | ||
- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/interpretation-active-expressions.js 369 (75) | ||
|
||
# Compilation | ||
- ast nodes 2281 = 730+1551 | ||
- sloc (471) = (169)+(302) | ||
|
||
[aexpr-source-transformation-propagation](https://github.com/active-expressions/aexpr-source-transformation-propagation.git) | ||
3154d05 | ||
3154d05af0ce410b041eb312ba57f7d32a6e7672 | ||
|
||
- https://lively-kernel.org/lively4/aexpr/../aexpr-source-transformation-propagation/src/./aexpr-source-transformation-propagation.js 730 (169) | ||
|
||
[babel-plugin-aexpr-source-transformation](https://github.com/active-expressions/babel-plugin-aexpr-source-transformation.git) | ||
54a712a | ||
54a712a45175f98c0f0a627770ae811759b195da | ||
|
||
- https://lively-kernel.org/lively4/aexpr/../babel-plugin-aexpr-source-transformation/./index.js 1551 (302) | ||
|
||
--- | ||
|
||
--- | ||
|
||
2820 + null | ||
|
||
all ref | ||
5794 = 1707 + 1267 + 2820 | ||
|
||
all aexpr | ||
3038 = 274 + 672 + 2092 | ||
|
||
interpret aexpr | ||
926 = 787 + 139 | ||
|
||
sum aexprs | ||
3964 = 3038 + 926 | ||
|
||
1707 - 274 | ||
1267 - 672 | ||
2820 - 2092 | ||
|
||
subsec:impl_comparison | ||
subsec:impl_complexity | ||
subsec:impl_qualitative_analysis | ||
subsec:impl_quantitative_analysis | ||
|
||
|
||
3018 = 2092 + 787 + 139 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
## 2024-07-18 Handwritten Text Recognition using AI | ||
*Author: @onsetsu* | ||
|
||
<script> | ||
const normalURL = lively4url + '/demos/stefan/handwritten-text-recognition/eng_bw.png'; | ||
const scribblyURL = lively4url + '/demos/stefan/handwritten-text-recognition/htr-test.png'; | ||
|
||
function textareaFor(text) { | ||
return <textarea style='width: 500px; height: 150px;'>{text}</textarea> | ||
} | ||
</script> | ||
|
||
### Using OpenAI | ||
|
||
<script> | ||
import OpenAI from "demos/openai/openai.js" | ||
|
||
async function textFromImageOpenAI(url) { | ||
let prompt = { | ||
"model": "gpt-4o", | ||
"max_tokens": 500, | ||
"temperature": 1, | ||
"top_p": 1, | ||
"n": 1, | ||
"stream": false, | ||
"stop": "VANILLA", | ||
"messages": [ | ||
{ "role": "system", "content": "You are a system for handwritten text recognition (htr). Given an image, extract the text in it and only answer with this text." }, | ||
{ "role": "user", "content": [ | ||
{ | ||
"type": "image_url", | ||
"image_url": { | ||
"url": url, | ||
"detail": "low" // high | ||
} | ||
} | ||
]} | ||
] | ||
} | ||
|
||
let json = await OpenAI.openAIRequest(prompt).then(r => r.json()) | ||
return json.choices[0].message.content | ||
} | ||
|
||
</script> | ||
|
||
![alt text](http://tesseract.projectnaptha.com/img/eng_bw.png "Handwritten Text"){width=400} | ||
|
||
<script> | ||
const text = await textFromImageOpenAI(normalURL) | ||
textareaFor(text) | ||
</script> | ||
|
||
![alt text](./../../../demos/stefan/handwritten-text-recognition/htr-test.png "Handwritten Text"){width=400} | ||
|
||
<script> | ||
const text2 = await textFromImageOpenAI(scribblyURL) | ||
textareaFor(text2) | ||
</script> | ||
|
||
### Using the OCR lib tesseract.js | ||
|
||
- Good for OCR, not for HTR | ||
- Has fine-grained feedback on where Words, lines, etc. are | ||
|
||
```javascript | ||
import { createWorker } from 'https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js' | ||
|
||
const worker = await createWorker('eng'); | ||
const ret = await worker.recognize(lively4url + '/demos/stefan/htr-test.png'); | ||
await worker.terminate(); | ||
ret.data.text | ||
``` | ||
|
||
<script> | ||
import { createWorker } from 'https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js' | ||
|
||
async function textFromURL(url) { | ||
const worker = await createWorker('eng'); | ||
const ret = await worker.recognize(url); | ||
await worker.terminate(); | ||
return ret | ||
} | ||
</script> | ||
|
||
Good for OCR-friendly text: | ||
|
||
<script> | ||
const ret = await textFromURL(normalURL) | ||
textareaFor(ret.data.text) | ||
</script> | ||
|
||
Bad for handwritten notes: | ||
|
||
<script> | ||
const ret = await textFromURL(scribblyURL) | ||
textareaFor(ret.data.text) | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"type":"Reference","version":"156251caf7bed39b90b263003775f7d9efb574f3","content":"## 2024-07-18 Handwritten Text Recognition using AI\n*Author: @onsetsu*\n\n<script>\nconst normalURL = lively4url + '/demos/stefan/handwritten-text-recognition/eng_bw.png';\nconst scribblyURL = lively4url + '/demos/stefan/handwritten-text-recognition/htr-test.png';\n\nfunction textareaFor(text) {\n return <textarea style='width: 500px; height: 150px;'>{text}</textarea>\n}\n</script>\n\n### Using OpenAI\n\n<script>\nimport OpenAI from \"demos/openai/openai.js\"\n \nasync function textFromImageOpenAI(url) {\n let prompt = {\n \"model\": \"gpt-4o\", \n \"max_tokens\": 500,\n \"temperature\": 1,\n \"top_p\": 1,\n \"n\": 1,\n \"stream\": false,\n \"stop\": \"VANILLA\",\n \"messages\": [\n { \"role\": \"system\", \"content\": \"You are a system for handwritten text recognition (htr). Given an image, extract the text in it and only answer with this text.\" },\n { \"role\": \"user\", \"content\": [\n {\n \"type\": \"image_url\",\n \"image_url\": {\n \"url\": url,\n \"detail\": \"low\" // high\n }\n }\n ]}\n ]\n }\n\n let json = await OpenAI.openAIRequest(prompt).then(r => r.json())\n return json.choices[0].message.content\n}\n\n</script>\n\n![alt text](http://tesseract.projectnaptha.com/img/eng_bw.png \"Handwritten Text\"){width=400}\n\n<script>\nconst text = await textFromImageOpenAI(normalURL)\ntextareaFor(text)\n</script>\n\n![alt text](./../../../demos/stefan/handwritten-text-recognition/htr-test.png \"Handwritten Text\"){width=400}\n\n<script>\nconst text2 = await textFromImageOpenAI(scribblyURL)\ntextareaFor(text2)\n</script>\n\n### Using the OCR lib tesseract.js\n\n- Good for OCR, not for HTR\n- Has fine-grained feedback on where Words, lines, etc. are\n\n```javascript\nimport { createWorker } from 'https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js'\n\nconst worker = await createWorker('eng');\nconst ret = await worker.recognize(lively4url + '/demos/stefan/htr-test.png');\nawait worker.terminate();\nret.data.text\n```\n\n<script>\nimport { createWorker } from 'https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js'\n\nasync function textFromURL(url) {\n const worker = await createWorker('eng');\n const ret = await worker.recognize(url);\n await worker.terminate();\n return ret\n}\n</script>\n\nGood for OCR-friendly text:\n\n<script>\nconst ret = await textFromURL(normalURL)\ntextareaFor(ret.data.text)\n</script>\n\nBad for handwritten notes:\n\n<script>\nconst ret = await textFromURL(scribblyURL)\ntextareaFor(ret.data.text)\n</script>\n\n"} | ||
{"from":1552,"to":1552,"name":"color","color":"#9ecae1"} | ||
{"from":1138,"to":1138,"name":"color","color":"#9ecae1"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/client/reactive/babel-plugin-sample-data-bindings/scribbles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const target = document.getElementById('target'); | ||
|
||
target.style.width <~ that.style.width | ||
|
||
|
||
|
||
|
||
|
||
|
||
ae(that.style.width).onChange(v => target.style.width = v) | ||
import { AExprRegistry } from 'src/client/reactive/active-expression/ae-registry.js' | ||
AExprRegistry.allAsArray().last.dispose() |
Oops, something went wrong.