Iminyaka embalwa edlule ibikhethekile kumamodeli e-AI asekelwe kuseva emaphakathi afana ne-ChatGPT, i-Gemini ye-Google, i-Microsoft's Copilot, njll. Akungabazeki ukuthi amamodeli anjalo e-AI aguqule izici eziningi. Kodwa ngakolunye uhlangothi, banezinye izici ezimbi. Mhlawumbe, uzwile futhi mayelana nokucisha okumbalwa kwe-ChatGPT .
Amamodeli asekelwe kuseva amaphakathi asengozini enkulu yephuzu elilodwa lokwehluleka. Kodwa manje, isikhathi sesishintshile. Ubuchwepheshe be-Blockchain buphinde buguqule izinkambu eziningi, kuhlanganise ne-artificial intelligence (AI).
I-Internet Computer Protocol (ICP) eyakhiwe yi-Dfinity, isebenzela ukusabalalisa i-AI ngokuvumela izinhlelo zokusebenza ze-AI ukuthi zisebenze nengqalasizinda yamafu ehlukaniswe ngokuphelele. Into ehlukile ukuthi, i-ICP ivumela amamodeli nezinsizakalo ze-AI ukuthi zisatshalaliswe kunethiwekhi yonkana yezikhungo zedatha ezizimele. Lolu hlobo lwendlela yokwahlukanisa luqinisekisa ukuthi imisebenzi ye-AI isobala, ayivimbeli ukucwaninga, futhi ayithambekele kangako ekuhlulekeni okukodwa.
Lesi sihloko sihluke ekuhlolweni okusebenzayo kwe- Face Recognition DApp esekelwe ku-ICP. Sizohlola ukuthi ukumiswa kwe-AI kusebenza kanjani ngokufanelekile ngemiboniso ecashile yesinyathelo ngasinye. Sizame ukwephula imiqondo yezobuchwepheshe eyinkimbinkimbi sibe izifundo eziqondakala kalula ngakho-ke ake siqale.
Yonke iphrojekthi yokuthuthukiswa kwephrojekthi kanye nezinqubo zokuhlola zenziwa emshinini osekelwe ku-Windows, ngakho-ke sakha uhlelo olungaphansi lwe-Linux lapha ngoba amathuluzi amaningi okuthuthukisa i-ICP nemibhalo yenzelwe izimo ezisekelwe ku-Linux.
📥Izimfuneko:
Isistimu Esebenzayo : IWindows ene-Windows Subsystem ye-Linux (WSL) ifakiwe. Sicela ubhekisele kulo mhlahlandlela ukuze ufake.
Ulwazi :
Ukuqonda okuyisisekelo kweJavaScript , React.js , Rust , kanye neWebAssembly .
Ukujwayelana nemiqondo yokuthuthukisa iwebhu.
Amathuluzi :
📥Misa Indawo Yokuthuthukisa:
sh -ci "$(curl -fsSL https://smartcontracts.org/install.sh)"
👉Ukuqinisekisa ukufakwa:
dfx –version
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env
👉Ukuqinisekisa ukufakwa, sebenzisa:
rustc –version
3. Faka i-Node.js ngokusebenzisa umyalo olandelayo:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt install -y nodejs
👉Ukuqinisekisa ukufakwa, sebenzisa:
node -v npm -v
git clone https://github.com/wasm-forge/wasi2ic.git cd wasi2ic cargo install --path .
👉Ukuze uhlole ukufakwa, sebenzisa:
echo $PATH wasi2ic –help
cargo install wasm-opt
📥Khipha iphrojekthi:
Sisebenzisa inqolobane yephrojekthi ye-GitHub ngezinjongo zethu zokuhlola. Ungahlola inqolobane yabo lapha .
1. Hlanganisa indawo yokugcina bese uzulazulela kuphrojekthi yokubona ubuso:
git clone https://github.com/dfinity/examples.git cd examples/rust/face-recognition
Qaphela: Ungafinyelela amafayela akho e-Linux subsystem ngokusesha \\wsl$
ku-File Explorer noma isici sokusesha esiqondile ku-Windows OS.
📥Landa Amamodeli Wokuqaphela Ubuso
Imodeli yokuthola ubuso izosetshenziswa ukuthola ubuso esithombeni. Gijima:
./download-face-detection-model.sh
Udinga ukuthekelisa imodeli ngefomethi ye-ONNX usebenzisa PyTorch
ne- facenet-pytorch
. Qala ngokufaka le mitapo yolwazi yePython:
pip install torch facenet-pytorch onnx
Qaphela: Uma i-Python ingakafakwa kusistimu yakho engaphansi, zama ukufaka i-Python ne-pip kusuka lapha: https://packaging.python.org/en/latest/tutorials/installing-packages/ .
Kufayela lePython noma igobolondo, sebenzisa okulandelayo: Thayipha i-python3 kutheminali bese usebenzisa ikhodi elandelayo. Ngemva kokubulawa, thayipha ukuphuma().
import torch import facenet_pytorch resnet = facenet_pytorch.InceptionResnetV1(pretrained='vggface2').eval() input = torch.randn(1, 3, 160, 160) torch.onnx.export(resnet, input, "face-recognition.onnx", verbose=False, opset_version=11)
Lokhu kuzokhiqiza ifayela le face-recognition.onnx
. Ikopishele kumsuka wenqolobane yakho.
📥Yakha
Manje, sekuyisikhathi sokwakha iphrojekthi. Gijima:
dfx start --background dfx deploy
Uma konke kuhamba kahle, ungabona i-URL ye-Frondend kutheminali.
Qaphela: Uma ubhekene nephutha elithile ngenxa yeklayenti elilahlekile, zama ukufaka webpack
kanye webpack-cli
emhlabeni jikelele usebenzisa i-npm:
sudo npm install -g webpack webpack-cli
Futhi, ukuncika kwendawo:
npm install
📥Dala i-canister, sebenzisa:
dfx canister create backend
Ungabona umlayezo olandelayo kutheminali.
👉Manje, ungabheka isimo se-backend ye-canister:
dfx canister status backend
Ungabona into efana nale kutheminali.
📥Ukulayishwa kweChunk kwamamodeli
Njengoba amamodeli e-AI ngokuvamile amakhulu. Azikwazi ukushumekwa ngokuqondile ku-WebAssembly (Wasm) kanambambili yenkontileka ehlakaniphile. Kunalokho, lawa mamodeli adinga ukulayishwa ngokwehlukana. Ukusingatha lokhu, i-DecideAI ithuthukise ithuluzi lokulayisha amamodeli ngokuqhubekayo. Ungathola ithuluzi lapha: ic-file-uploader .
👉Ukufaka ithuluzi, sebenzisa umyalo olandelayo:
cargo install ic-file-uploader
Uma isifakiwe, ungasebenzisa i- upload-models-to-canister.sh
script ngokusebenzisa ./upload-models-to-canister.sh
kutheminali ukuze ulayishe amamodeli. Lesi script senza izinyathelo ezilandelayo:
dfx canister call backend clear_face_detection_model_bytes dfx canister call backend clear_face_recognition_model_bytes
ic-file-uploader backend append_face_detection_model_bytes version-RFB-320.onnx ic-file-uploader backend append_face_recognition_model_bytes face-recognition.onnx
dfx canister call backend setup_models
Manje, usungakwazi ukusebenzisana ne-Frontind ngokusebenzisa i-URL oyithole kutheminali ngenkathi dfx deploy
command (Umfanekiso 1)
Uma usulayishe isithombe ngokuchofoza kulogo ye-ICP, zama ukwengeza igama lomuntu ngokuchofoza inkinobho ethi “ Engeza umuntu ” ukuze uqeqeshe imodeli.
Ibona ubuso obunophawu oluzenzakalelayo lukanxande ebusweni. Uma usetha igama, libonisa umlayezo wokwengeza okuyimpumelelo njengokulandelayo:
I-AI ikhumbula igama olisethele ubuso ukuze ukwazi ukuhlola ukuthi ingabe ihlonza ubuso bezithombe ezihlukene zomuntu oyedwa noma cha. Lapha, izithombe ezahlukene zikaNikola Tesla zithathwa. Ukuze ulayishe esinye Isithombe ukuze sitholwe ubuso, layisha kabusha ikhasi, bese uchofoza inketho ethi “ Bona ”. Asibone; ikhombe ngempumelelo ubuso bukaNikola Tesla ngomehluko omncane kusukela kowokuqala.
Lapha, isithombe esenziwe nge-AI sika-Nikola Tesla sihanjiswa kumodeli, futhi ngokumangalisayo, sithole ngokunembile ubuso, ake sibone lapha:
Iqinisekise ngempumelelo ukuthi i-ICP Face Recognizing DApp isebenza kahle njengoba ithole ngempumelelo ubuso buka-Nikola Tesla. Ungakuzama wedwa.
Njengoba ingeyezinjongo zokuhlola, i-UI nezici kunqunyelwe. Ungakwazi ukwengeza izici ezengeziwe namasevisi uma uphuthuma ukwakha i-dApp elungele ukukhiqiza ku-ICP ngezinjongo zokubuka ubuso. Ungazama izici ezilandelayo ngezibonelo zekhodi. Sicela uqaphele ukuthi kufanele wengeze noma wenze ngendlela oyifisayo amakhodi ngokwezidingo zakho.
📥Nawa amathiphu akho:
Uma ungeza lesi sici kule dApp, abasebenzisi ababhalisiwe kuphela abakwazi ukufinyelela i-DApp. Nansi indlela ongakwengeza ngayo ubuqiniso usebenzisa i-Internet Identity. Ungakwazi ukuhlanganisa ubunikazi be-inthanethi ngokungeza inkinobho yokungena ye-Inthanethi ekhasini eliyisiqalo. Uma umsebenzisi esengenile, bonisa ideshibhodi yomuntu siqu.
Ungeza kanjani:
👉Faka ukuncika kobunikazi be-inthanethi:
npm install @dfinity/agent @dfinity/auth-client
👉Engeza ikhodi elandelayo ku-frontend yakho ukuze unike amandla ubuqiniso:
import { AuthClient } from "@dfinity/auth-client"; async function init() { const authClient = await AuthClient.create(); if (await authClient.isAuthenticated()) { // Display dashboard or personalized content } else { authClient.login({ identityProvider: "https://identity.ic0.app/#authorize", onSuccess: () => { // Once authenticated, display personalized features }, }); } } init();
👉Ngemva kokungena ngemvume, umsebenzisi angabona umlando wabo wobuso obaziwayo noma enye idatha yomuntu siqu.
Yenza umsebenzi wokulayisha isithombe futhi wenze kube lula ngokuvumela abasebenzisi ukuthi bahudule futhi bawise izithombe ukuze zitholwe ubuso.
Ungeza kanjani :
👉Sebenzisa umsebenzi we-HTML5 wokudonsa nokuwisa:
<div id="drop-area"> <p>Drag and drop an image here or click to select</p> <input type="file" id="file-input" hidden /> </div>
👉Engeza i-JavaScript ukuze ubambe isenzo sokudonsa nokuwisa:
const dropArea = document.getElementById("drop-area"); dropArea.addEventListener("dragover", (event) => { event.preventDefault(); }); dropArea.addEventListener("drop", (event) => { event.preventDefault(); const files = event.dataTransfer.files; // Process the uploaded image });
👉Qiniseka ukuthi ihlangana kahle nomsebenzi wakho okhona wokuthola ubuso.
Kuzoba isici esibandakanyayo ukubonisa ibha yokuqhubeka uma isithombe silayishwa ukuze sazise abasebenzisi ukuthi isistimu icubungula isithombe.
Ungeza kanjani:
👉Sebenzisa ibha yenqubekelaphambili ye-HTML elula:
<div id="progress-bar"> <div id="progress-fill" style="width: 0%;"></div> </div>
👉Buyekeza ngokunamandla ibha yokuqhubeka njengoba isithombe sicutshungulwa:
const progressFill = document.getElementById("progress-fill"); let progress = 0; const interval = setInterval(() => { progress += 10; progressFill.style.width = `${progress}%`; if (progress === 100) { clearInterval(interval); } }, 100); // Simulate progress every 100ms
Ungakwazi ukwengeza isici ukuze unikeze izaziso zesikhathi sangempela uma ukubonwa kobuso sekuqedile, ngesaziso se-modal noma se-toast.
Ungeza kanjani :
👉 Ungasebenzisa umtapo wezincwadi ongasindi njenge -Toastr noma izaziso zethosti yangokwezifiso.
<div id="notification" class="hidden">Face Recognition Complete!</div>
👉Ku-JavaScript yakho, bonisa isaziso lapho i-backend ibuyisela umphumela:
function showNotification(message) { const notification = document.getElementById("notification"); notification.innerHTML = message; notification.classList.remove("hidden"); setTimeout(() => { notification.classList.add("hidden"); }, 3000); // Hide notification after 3 seconds } // Call this after face recognition is done showNotification("Face detected and recognized!");
📥Izinyathelo Zokugcina: Yakha kabusha futhi Usebenzise
Ngemva kokwenza lezi zici ezintsha:
👉Yakha kabusha iphrojekthi:
dfx build
👉Thumela ku-testnet: Iwukuhlola kuqala ngaphambi kokuphuthuma ku-mainnet.
dfx deploy --network ic
Lezi yizibonelo ezimbalwa kanye nemibono ngezinjongo zokubonisa. Ungazivivinya uwedwa futhi usazise ukuqhubeka kwakho esigabeni sokuphawula. Futhi, ungenza okwengeziwe ngayo ukusabalalisa i-AI ku-ICP.
Sihlole ngempumelelo i-Face Recognizing DApp ku-ICP okuwumzamo wangempela wokusabalalisa i-AI (DeAI). Njengokuhlolwa kwethu, izimpendulo ze-DApp zazishesha, futhi ukutholwa kobuso kwakunembayo. Ingqalasizinda eyingqayizivele ye-ICP ingasisiza ekwenzeni imisebenzi eyinkimbinkimbi efana nokubona ubuso ngaphandle kokuthembela kumasistimu aphakathi nendawo.
Akugcini nje ngokuthuthukisa ukuphepha nobumfihlo kodwa futhi kukhombisa amandla ezinhlelo zokusebenza ze-AI (DeAI) ezisatshalaliswayo ukuthi ziguquke ngokushesha. Njengoba i-ICP iqhubeka nokuthuthuka, ikhono lokusebenzisa amamodeli amakhulu nokwenza inkomba ye-AI on-chain kungavula amathuba amasha okwenziwa okusha. Singalindela i-AI ehlukaniselwe ukuba ngumdlali obalulekile esikhathini esizayo sezixazululo ezinokwethenjelwa nezinokwehla. Onjiniyela futhi banamathuba amasha okudala imikhiqizo eminingi namasevisi ku-ICP.