Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

CANISTER=$1
echo Compiling for $CANISTER
cargo build --release --target wasm32-unknown-unknown --package $CANISTER
candid-extractor target/wasm32-unknown-unknown/release/$CANISTER.wasm > src/$CANISTER/$CANISTER.did
dfx generate $CANISTER
1 change: 1 addition & 0 deletions src/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ crate-type = ["cdylib"]
[dependencies]
candid = "0.10"
ic-cdk = "0.17"
serde = "1.0.216"
18 changes: 16 additions & 2 deletions src/backend/backend.did
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
service : {
"greet": (text) -> (text) query;
type Art = record { name : text; description : text; image : text };
type Artist = record { name : text; collections : vec Collection };
type Collection = record { arts : vec Art; name : text; description : text };
type DetectionAtom = record { art : Art; confidence : nat32 };
type DetectionReport = record { similarities : vec DetectionAtom };
service : () -> {
get_detection_progress : (nat32) -> (nat32) query;
get_detection_result : (nat32) -> (DetectionReport) query;
get_inspiration_progress : (nat32) -> (nat32) query;
get_inspiration_result : (nat32) -> (text) query;
get_random_artists : (nat32) -> (vec Artist) query;
get_random_arts : (nat32) -> (vec Art) query;
get_random_collections : (nat32) -> (vec Collection) query;
update_detection_inference_session : () -> (nat32);
update_detection_session_data : (nat32, text) -> (bool);
update_inspiration_inference_session : (text) -> (nat32);
}
18 changes: 16 additions & 2 deletions src/backend/declarations/backend.did
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
service : {
"greet": (text) -> (text) query;
type Art = record { name : text; description : text; image : text };
type Artist = record { name : text; collections : vec Collection };
type Collection = record { arts : vec Art; name : text; description : text };
type DetectionAtom = record { art : Art; confidence : nat32 };
type DetectionReport = record { similarities : vec DetectionAtom };
service : () -> {
get_detection_progress : (nat32) -> (nat32) query;
get_detection_result : (nat32) -> (DetectionReport) query;
get_inspiration_progress : (nat32) -> (nat32) query;
get_inspiration_result : (nat32) -> (text) query;
get_random_artists : (nat32) -> (vec Artist) query;
get_random_arts : (nat32) -> (vec Art) query;
get_random_collections : (nat32) -> (vec Collection) query;
update_detection_inference_session : () -> (nat32);
update_detection_session_data : (nat32, text) -> (bool);
update_inspiration_inference_session : (text) -> (nat32);
}
26 changes: 25 additions & 1 deletion src/backend/declarations/backend.did.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ import type { Principal } from '@dfinity/principal';
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface _SERVICE { 'greet' : ActorMethod<[string], string> }
export interface Art {
'name' : string,
'description' : string,
'image' : string,
}
export interface Artist { 'name' : string, 'collections' : Array<Collection> }
export interface Collection {
'arts' : Array<Art>,
'name' : string,
'description' : string,
}
export interface DetectionAtom { 'art' : Art, 'confidence' : number }
export interface DetectionReport { 'similarities' : Array<DetectionAtom> }
export interface _SERVICE {
'get_detection_progress' : ActorMethod<[number], number>,
'get_detection_result' : ActorMethod<[number], DetectionReport>,
'get_inspiration_progress' : ActorMethod<[number], number>,
'get_inspiration_result' : ActorMethod<[number], string>,
'get_random_artists' : ActorMethod<[number], Array<Artist>>,
'get_random_arts' : ActorMethod<[number], Array<Art>>,
'get_random_collections' : ActorMethod<[number], Array<Collection>>,
'update_detection_inference_session' : ActorMethod<[], number>,
'update_detection_session_data' : ActorMethod<[number, string], boolean>,
'update_inspiration_inference_session' : ActorMethod<[string], number>,
}
export declare const idlFactory: IDL.InterfaceFactory;
export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
47 changes: 46 additions & 1 deletion src/backend/declarations/backend.did.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
export const idlFactory = ({ IDL }) => {
return IDL.Service({ 'greet' : IDL.Func([IDL.Text], [IDL.Text], ['query']) });
const Art = IDL.Record({
'name' : IDL.Text,
'description' : IDL.Text,
'image' : IDL.Text,
});
const DetectionAtom = IDL.Record({ 'art' : Art, 'confidence' : IDL.Nat32 });
const DetectionReport = IDL.Record({
'similarities' : IDL.Vec(DetectionAtom),
});
const Collection = IDL.Record({
'arts' : IDL.Vec(Art),
'name' : IDL.Text,
'description' : IDL.Text,
});
const Artist = IDL.Record({
'name' : IDL.Text,
'collections' : IDL.Vec(Collection),
});
return IDL.Service({
'get_detection_progress' : IDL.Func([IDL.Nat32], [IDL.Nat32], ['query']),
'get_detection_result' : IDL.Func(
[IDL.Nat32],
[DetectionReport],
['query'],
),
'get_inspiration_progress' : IDL.Func([IDL.Nat32], [IDL.Nat32], ['query']),
'get_inspiration_result' : IDL.Func([IDL.Nat32], [IDL.Text], ['query']),
'get_random_artists' : IDL.Func([IDL.Nat32], [IDL.Vec(Artist)], ['query']),
'get_random_arts' : IDL.Func([IDL.Nat32], [IDL.Vec(Art)], ['query']),
'get_random_collections' : IDL.Func(
[IDL.Nat32],
[IDL.Vec(Collection)],
['query'],
),
'update_detection_inference_session' : IDL.Func([], [IDL.Nat32], []),
'update_detection_session_data' : IDL.Func(
[IDL.Nat32, IDL.Text],
[IDL.Bool],
[],
),
'update_inspiration_inference_session' : IDL.Func(
[IDL.Text],
[IDL.Nat32],
[],
),
});
};
export const init = ({ IDL }) => { return []; };
124 changes: 122 additions & 2 deletions src/backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,124 @@
use candid::{CandidType};
use serde::{Serialize, Deserialize};

#[derive(CandidType, Deserialize, Serialize, Clone)]
struct Art {
name: String,
description: String,
image: String
}

#[derive(CandidType, Deserialize, Serialize, Clone)]
struct Collection {
name: String,
description: String,
arts: Vec<Art>
}

#[derive(CandidType, Deserialize, Serialize, Clone)]
struct Artist {
name: String,
collections: Vec<Collection>
}

#[derive(CandidType, Deserialize)]
struct DetectionAtom {
art: Art,
confidence: u32
}

#[derive(CandidType, Deserialize)]
struct DetectionReport {
similarities: Vec<DetectionAtom>
}

#[derive(Default)]
#[derive(CandidType, Deserialize, Serialize, Clone)]
struct State {
artists: Vec<Artist>,
collections: Vec<Collection>,
arts: Vec<Art>
}

thread_local! {
static STATE: std::cell::RefCell<State> = std::cell::RefCell::default();
}

///////////////////////////////////////////////////////////////////

#[ic_cdk::init]
fn init() {
STATE.with(|state| {
*state.borrow_mut() = State {
artists: vec![],
collections: vec![],
arts: vec![]
};
});
}

#[ic_cdk::pre_upgrade]
fn pre_upgrade() {
STATE.with(|state| {
let state = state.borrow();
ic_cdk::storage::stable_save((
state.clone(),
)).expect("Failed to save states");
});
}

#[ic_cdk::post_upgrade]
fn post_upgrade() {
let (state,): (State,) = ic_cdk::storage::stable_restore().expect("Failed to restore state");
STATE.with(|s| {
*s.borrow_mut() = state;
});
}

///////////////////////////////////////////////////////////////////

#[ic_cdk::query]
fn get_random_artists(amount: u32) -> Vec<Artist> {
return vec![];
}

#[ic_cdk::query]
fn get_random_collections(amount: u32) -> Vec<Collection> {
return vec![];
}

#[ic_cdk::query]
fn get_random_arts(amount: u32) -> Vec<Art> {
return vec![];
}

///////////////////////////////////////////////////////////////////

#[ic_cdk::update]
fn update_inspiration_inference_session(prompt: String) -> u32 { 0 }

#[ic_cdk::query]
fn get_inspiration_progress(session_id: u32) -> u32 { 0 }

#[ic_cdk::query]
fn get_inspiration_result(session_id: u32) -> String { "".to_string() }

///////////////////////////////////////////////////////////////////

#[ic_cdk::update]
fn update_detection_inference_session() -> u32 { 0 }

#[ic_cdk::update]
fn update_detection_session_data(id: u32, data: String) -> bool { false }

#[ic_cdk::query]
fn get_detection_progress(id: u32) -> u32 { 0 }

#[ic_cdk::query]
fn greet(name: String) -> String {
format!("Hello, {}!", name)
fn get_detection_result(id: u32) -> DetectionReport {
DetectionReport { similarities: vec![] }
}

///////////////////////////////////////////////////////////////////

ic_cdk::export_candid!();