-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MPR Preview first mockup after updating image
Preview first mockup after updating image
- Loading branch information
Showing
11 changed files
with
361 additions
and
37 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from .image import mockup as startMockup # noqa: F401 | ||
from .image import previewMockup # noqa: F401 |
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
Binary file not shown.
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,69 @@ | ||
importScripts("https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"); | ||
|
||
async function initianPyodide() { | ||
console.log("start startup"); | ||
const pyodide = await loadPyodide(); | ||
await pyodide.loadPackage(["numpy", "opencv-python", "pillow", "micropip"]); | ||
let zipResponse = await fetch("/mockup.zip"); | ||
let zipBinary = await zipResponse.arrayBuffer(); | ||
pyodide.unpackArchive(zipBinary, "zip"); | ||
await pyodide.runPythonAsync( | ||
` | ||
from pyodide.http import pyfetch | ||
response = await pyfetch("/image_process.py") | ||
with open("./image_process.py", "wb") as f: | ||
f.write(await response.bytes()) | ||
`, | ||
(output) => console.log(output), | ||
(output) => console.log(output), | ||
); | ||
console.log("end up"); | ||
return pyodide; | ||
} | ||
|
||
// Now only the first orientation model is generated for preview | ||
async function runPreviewMockup(pyodide) { | ||
let pythonNamespace = pyodide.globals.get("dict")(); | ||
await pyodide.runPythonAsync( | ||
` | ||
import mockup | ||
import image_process | ||
from js import locationKey, imageUpload, deviceInfo, deviceId | ||
origin_image_path = await image_process.upload_file() | ||
print("start preview", origin_image_path) | ||
output_img = await mockup.previewMockup(locationKey, deviceId, origin_image_path, deviceInfo) | ||
`, | ||
{ globals: pythonNamespace }, | ||
); | ||
pyodide.runPython( | ||
` | ||
temp = image_process.save_image(output_img) | ||
`, | ||
{ globals: pythonNamespace }, | ||
); | ||
return pythonNamespace.get("temp").toJs(); | ||
} | ||
|
||
async function main() { | ||
let pyodideObject = initianPyodide(); | ||
self.onmessage = async (event) => { | ||
pyodideObject = await pyodideObject; | ||
|
||
self["imageUploadList"] = undefined; | ||
self["imageUpload"] = event.data.imageUpload; | ||
self["locationKey"] = event.data.location; | ||
self["deviceId"] = event.data.deviceId; | ||
self["deviceInfo"] = event.data.deviceInfo; | ||
|
||
try { | ||
// TODO: Handle preview loading state in widget | ||
let results = await runPreviewMockup(pyodideObject); | ||
console.log("preview results", results); | ||
self.postMessage(results); | ||
} catch (error) { | ||
self.postMessage({ error: error.message }); | ||
} | ||
}; | ||
} | ||
|
||
main(); |
Oops, something went wrong.