diff --git a/blockchain/generate_data.py b/blockchain/generate_data.py index 1dba046..3aaf5ac 100644 --- a/blockchain/generate_data.py +++ b/blockchain/generate_data.py @@ -40,7 +40,7 @@ test_data = dataset.data for i, tensor in enumerate(test_data): - img = transforms.ToPILImage()(tensor) + img = transforms.ToPILImage()(test_data[1]) base64_img = base64.b64encode(img.tobytes()) img.save("data/" + str(i) + ".png") break diff --git a/client/src/App.js b/client/src/App.js index abd9b2f..0a8fa9a 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -25,8 +25,8 @@ function App() { {auth ? null : } />} {auth ? null : } />} {auth ? } /> : null} - {auth ? } /> : null} - {auth ? } /> : null} + {auth ? } /> : null} + {auth ? } /> : null} {auth ? } /> : null} {auth ? } /> : null} {auth ? } /> : } />} diff --git a/client/src/components/NavBar.jsx b/client/src/components/NavBar.jsx index 3c3fe9a..4a613ed 100644 --- a/client/src/components/NavBar.jsx +++ b/client/src/components/NavBar.jsx @@ -36,8 +36,8 @@ function NavBar() { ) : null} {auth ? (
  • - - Datasets + + Create a Dataset
  • ) : null} diff --git a/client/src/pages/CreateDatasetPage.jsx b/client/src/pages/CreateDatasetPage.jsx index fe94bdb..6b3e47f 100644 --- a/client/src/pages/CreateDatasetPage.jsx +++ b/client/src/pages/CreateDatasetPage.jsx @@ -7,8 +7,10 @@ import { getDataset, createDataset } from "../api/dataset"; import { DataContext } from "../components/DataProvider"; +import styles from "../styles/pages/CreateDatasetPage.module.css"; + function CreateDatasetPage() { - document.title = "Create Dataset | SeBRUS"; + document.title = "Create a Dataset | SeBRUS"; const navigate = useNavigate(); @@ -77,20 +79,26 @@ function CreateDatasetPage() { return (
    -

    Create Dataset

    - setName(e.target.value)} - /> - setDescription(e.target.value)} - /> - +
    +

    Create Dataset

    + setName(e.target.value)} + /> + setDescription(e.target.value)} + /> + +
    ); } diff --git a/client/src/pages/DashboardPage.jsx b/client/src/pages/DashboardPage.jsx index 5897a22..45da4dc 100644 --- a/client/src/pages/DashboardPage.jsx +++ b/client/src/pages/DashboardPage.jsx @@ -63,7 +63,7 @@ function DashboardPage() { let imageCount = await DatasetContract.methods.getImageCount().call(); for (let j = 0; j < imageCount; j++) { - let imageAddress = await DatasetContract.methods.getImages(j).call(); + let imageAddress = await DatasetContract.methods.getImage(j).call(); let ImageContract = await new window.web3.eth.Contract( imageABI, @@ -94,36 +94,18 @@ function DashboardPage() { return (

    Datasets

    -
      - {datasets.map((dataset) => { +
        + {datasets.map((dataset, index) => { console.log(dataset); return ( -
      • -

        {dataset.name}

        -

        {dataset.description}

        +
      • +

        Dataset name: {dataset.name}

        +

        + Description: {dataset.description} +

        - Link + Link

        -

        Images:

        -
          - {dataset.images.map((image) => { - console.log(image); - return ( -
        • -

          {image.class}

          -

          - {image.value.substring(0, 22) === - "data:image/png;base64," ? ( - {image.class} - ) : ( - image.value - )} -

          -

          {image.approved ? "Approved" : "Not Approved"}

          -
        • - ); - })} -
      • ); })} diff --git a/client/src/pages/DatasetPage.jsx b/client/src/pages/DatasetPage.jsx index b48f56a..375eec7 100644 --- a/client/src/pages/DatasetPage.jsx +++ b/client/src/pages/DatasetPage.jsx @@ -1,36 +1,151 @@ import { useEffect, useState } from "react"; +import web3 from "web3"; + // import { Grid } from "react-visual-grid"; import { Image } from "../components/Image"; +import { getABI } from "../api/abi"; +import { getDataset } from "../api/dataset"; + +import { DataContext } from "../components/DataProvider"; import styles from "../styles/pages/DatasetPage.module.css"; import dog from "../assets/dog1.png"; function DatasetPage() { - document.title = "Dataset | SeBRUS"; + document.title = "Datasets | SeBRUS"; const [id, setId] = useState(null); - const [images, setImage] = useState([ - { text: "../assets/dog1.png" }, - { text: "../assets/dog2.png" }, - { text: "../assets/dog3.png" }, - ]); - //code the img retrieval - // add key - - const addList = () => { - const newImage = { id: Math.random(), text: "New todo" }; - setImage([images, newImage]); - }; + const [dataImages, setDataImages] = useState([]); + + const verifyImage = (index) => { + const load = async () => { + let datasetABI = await getABI("1"); + let imageABI = await getABI("2"); + + if (datasetABI === null || imageABI === null) { + alert("Error loading dataset manager or dataset ABI."); + return; + } + + window.web3 = new web3(window.ethereum); + + const urlParams = new URLSearchParams(window.location.search); + let id = urlParams.get("id"); + setId(id); + + if (id === null) { + alert("ID not found."); + return; + } + + let dataset = await getDataset(id); + if (dataset === null) { + alert("Dataset not found."); + return; + } + + console.log(dataset); + + let DatasetContract = new window.web3.eth.Contract( + datasetABI, + dataset[0].address, + ); + + let image = await DatasetContract.methods.getImage(index); + let address = await image.call(); + let ImageContract = new window.web3.eth.Contract(imageABI, address); + await ImageContract.methods + .approve() + .send({ from: window.ethereum.selectedAddress }); + + let images = []; + let imageCount = await DatasetContract.methods.getImageCount().call(); + + for (let j = 0; j < imageCount; j++) { + let imageAddress = await DatasetContract.methods.getImage(j).call(); + + let ImageContract = await new window.web3.eth.Contract( + imageABI, + imageAddress, + ); + + let image = { + class: await ImageContract.methods.getClass().call(), + value: await ImageContract.methods.getValue().call(), + approved: await ImageContract.methods.getApproved().call(), + }; + + images.push(image); + } + setDataImages(images); - console.log(id); + alert("Image approved."); + }; + + load(); + }; useEffect(() => { - const urlParams = new URLSearchParams(window.location.search); - let id = urlParams.get("id"); - setId(id); + const load = async () => { + let datasetABI = await getABI("1"); + let imageABI = await getABI("2"); + + if (datasetABI === null || imageABI === null) { + alert("Error loading dataset manager or dataset ABI."); + return; + } + + window.web3 = new web3(window.ethereum); + + const urlParams = new URLSearchParams(window.location.search); + let id = urlParams.get("id"); + setId(id); + + if (id === null) { + alert("ID not found."); + return; + } + + let dataset = await getDataset(id); + if (dataset === null) { + alert("Dataset not found."); + return; + } + + console.log(dataset); + + let images = []; + + let DatasetContract = new window.web3.eth.Contract( + datasetABI, + dataset[0].address, + ); + + let imageCount = await DatasetContract.methods.getImageCount().call(); + + for (let j = 0; j < imageCount; j++) { + let imageAddress = await DatasetContract.methods.getImage(j).call(); + + let ImageContract = await new window.web3.eth.Contract( + imageABI, + imageAddress, + ); + + let image = { + class: await ImageContract.methods.getClass().call(), + value: await ImageContract.methods.getValue().call(), + approved: await ImageContract.methods.getApproved().call(), + }; + + images.push(image); + } + setDataImages(images); + }; + + load(); }, []); if (id === null) { @@ -45,24 +160,17 @@ function DatasetPage() {
          - {images.map((images, index) => ( -
        • {images.text}
        • + {dataImages.map((image, index) => ( +
        • +

          {image.class}

          + {image.class + +
        • ))}
        - {/* ; */} - {"test + {/* {data && data.length>0 && data.map((item)=>

        {item.about}

        )} */} {"ID:" + id} diff --git a/client/src/styles/pages/ContributePage.module.css b/client/src/styles/pages/ContributePage.module.css index 5adaf6d..e4d171b 100644 --- a/client/src/styles/pages/ContributePage.module.css +++ b/client/src/styles/pages/ContributePage.module.css @@ -6,7 +6,7 @@ width: 40vw; padding-bottom: 30px; overflow-x: visible; - overflow-y:auto; + overflow-y: auto; } .header { @@ -15,31 +15,32 @@ } .image { - width:90%; + width: 90%; object-fit: contain; } .file { - margin: 1rem auto; - display: block; + margin: 1rem auto; + display: block; } .label { - display: block; - margin: 2rem auto; - padding: 1rem; - border-radius: 1rem; + display: block; + margin: 2rem auto; + padding: 1rem; + border-radius: 1rem; + height: 5px; } .uploader { - font-family: Verdana, sans-serif; - border-radius: 30px; - border-color: black; - width: 300px; - height: 40px; - font-size: 12pt; - color: 282c34; - margin: 0 px; - bottom: 0px; - background-color: snow; + font-family: Verdana, sans-serif; + border-radius: 30px; + border-color: black; + width: 300px; + height: 40px; + font-size: 12pt; + color: 282c34; + margin: 0 px; + bottom: 0px; + background-color: snow; } diff --git a/client/src/styles/pages/CreateDatasetPage.module.css b/client/src/styles/pages/CreateDatasetPage.module.css new file mode 100644 index 0000000..00fb2db --- /dev/null +++ b/client/src/styles/pages/CreateDatasetPage.module.css @@ -0,0 +1,36 @@ +.create { + background-color: #282c34; + color: snow; + margin: 50px; + border-radius: 30px; + width: 40vw; + padding-bottom: 30px; + overflow-x: visible; + overflow-y: auto; +} + +.header { + color: snow; + margin-top: 30px; + margin-bottom: 80px; +} + +.box { + display: block; + margin: 1rem auto; + padding: 1rem; + width: 200px; + border-radius: 1rem; +} + +.button { + font-family: Verdana, sans-serif; + border-radius: 30px; + border-color: black; + width: 300px; + height: 40px; + font-size: 12pt; + color: 282c34; + margin-top: 50px; + background-color: snow; +} \ No newline at end of file diff --git a/client/src/styles/pages/DashboardPage.module.css b/client/src/styles/pages/DashboardPage.module.css index e69de29..dcc5ce3 100644 --- a/client/src/styles/pages/DashboardPage.module.css +++ b/client/src/styles/pages/DashboardPage.module.css @@ -0,0 +1,7 @@ +.list { + text-align: left; +} + +.datasets { + +} \ No newline at end of file