Skip to content

Commit

Permalink
plant identification complete
Browse files Browse the repository at this point in the history
  • Loading branch information
JaberHPranto committed Oct 12, 2021
1 parent 00b9382 commit 6d914cc
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 6 deletions.
138 changes: 138 additions & 0 deletions client/package-lock.json

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

2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"axios": "^0.21.1",
"bootstrap": "^5.0.1",
"concurrently": "^6.2.0",
"image-to-base64": "^2.2.0",
"react": "^17.0.2",
"react-bootstrap": "^1.6.1",
"react-dom": "^17.0.2",
"react-file-base64": "^1.0.3",
"react-google-login": "^5.2.2",
"react-html-parser": "^2.0.2",
"react-redux": "^7.2.4",
Expand Down
63 changes: 63 additions & 0 deletions client/src/components/PlantIdentify/PIDetailsModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useState } from 'react';
import { Button, Modal } from 'react-bootstrap';
import "../../styles/plant-identify.css";

function PIDetailsModal({ name, desc, synonyms, taxonomy, authority, common_names }) {
const [show, setShow] = useState(false);

const handleClose = () => setShow(false);
const handleShow = () => setShow(true);

return (
<>
<Button className="bg-col-primary pi-modal-btn" onClick={handleShow}>
Details
</Button>

<Modal show={show} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title className="pi-mt">{name}</Modal.Title>
{authority}
</Modal.Header>
<Modal.Body className="pi-mb">
<h5>Common Names</h5>
{common_names.map(cn => (
<div key={cn} className="pi-mb-cn">{cn}</div>
))}
</Modal.Body>

<Modal.Body className="pi-mb" >
<h5>Description</h5>
<div className="pi-mb-desc">{desc}</div>
</Modal.Body>
<Modal.Body className="pi-mb">
<h5>Taxonomy</h5>
<div className="pi-mb-tax">
<div><span>Kingdom: </span>{taxonomy.kingdom}</div>
<div><span>Phylum: </span>{taxonomy.phylum}</div>
<div><span>Class: </span>{taxonomy.class}</div>
<div><span>Order: </span>{taxonomy.order}</div>
<div><span>Family: </span>{taxonomy.family}</div>
<div><span>Genus: </span>{taxonomy.genus}</div>
</div>
</Modal.Body>

<Modal.Body className="pi-mb">
<h5>Synonyms</h5>
{synonyms.map(syn => (
<div className="pi-mb-syn" key={syn}>{syn}</div>
))}
</Modal.Body>

<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
</Modal.Footer>

</Modal>
</>
);
}

export default PIDetailsModal
102 changes: 102 additions & 0 deletions client/src/components/PlantIdentify/PlantIdentify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import axios from 'axios';
import React, { useState } from 'react';
import { Button, Col, Form, Row } from 'react-bootstrap';
import FileBase64 from 'react-file-base64';
import "../../styles/plant-identify.css";
import Loader from "../Ecommerce/Loader";
import PIDetailsModal from './PIDetailsModal';

function PlantIdentify() {
const [file, setFile] = useState()
const [imageUrl, setImageUrl] = useState("")
const [plantSuggestion, setPlantSuggestion] = useState([])
const [loading, setLoading] = useState(false)

const handleFileInput = (e) => {
e.preventDefault()
getPlantInfo()
setLoading(true)
}

const getPlantInfo = async () => {
try {
const {data} = await axios.post(`/api/identify-plant`, { file })
setImageUrl(data.imageUrl)
setPlantSuggestion(data.plantSuggestions)
setLoading(false)
} catch (error) {
console.log('Error',error);
}
}

// console.log(imageUrl);
console.log(plantSuggestion);


return (
<div>
<Form onSubmit={handleFileInput} className='pi-form'>
<FileBase64 type="file" multiple={false} onDone={
({ base64 }) => setFile(base64)} />

<Button type='submit' className='bg-col-primary'>
Upload
</Button>
</Form>

{loading ? <Loader /> : (
<>
{imageUrl &&
<div className="pi-mainImg">
<img src={imageUrl} alt="pi-img" />
</div>
}

{plantSuggestion &&
<div>
{plantSuggestion.map(plant => (
<Row key={plant.id} className="pi-plants">
<Col className="pi-plants-info" md={5} sm={12}>
<div className="pi-plants-img" >
{plant.similar_images.map(i =>
(
<img src={i.url} alt="plant-img" key={i.id} />
)
)}
</div>
</Col>
<Col md={5} sm={6} className="pi-col-2">
<div className='pi-card-info'>
<h3 className="pi-name">{plant.plant_name}</h3>
<div><span>Scientific Name:</span>{plant.plant_details.scientific_name}</div>
<div><span>Genus:</span>{plant.plant_details.structured_name.genus}</div>
<div><span>Species:</span>{plant.plant_details.structured_name.species}</div>

<div className="pi-col-2-info">
<PIDetailsModal name={plant.plant_name} authority={plant.plant_details.name_authority} common_names={plant.plant_details.common_names} synonyms={plant.plant_details.synonyms} taxonomy={plant.plant_details.taxonomy} desc={plant.plant_details.wiki_description.value} />
<a href={plant.plant_details.url}><i className="fas fa-globe"></i> </a>
</div>
</div>
</Col>
<Col md={2} sm={6}>
<div className="pi-probability">
<p>{`${((plant.probability).toFixed(2)) * 100} %`}</p>
</div>

</Col>
</Row>
))}
</div>

}

</>

)}


</div>
)
}

export default PlantIdentify
7 changes: 3 additions & 4 deletions client/src/components/PlantSearch/PlantDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ function PlantDetails({ match }) {
fetchPlant()

}, [match])
console.log(plantData)
return (
<div>
{plantData && (
<Table striped bordered>
<Table striped bordered style={{marginTop:'-1.5rem'}}>
<thead>
</thead>
<tbody className='ps-table-info'>
Expand Down Expand Up @@ -53,11 +52,11 @@ function PlantDetails({ match }) {
</tr>
<tr>
<td>Row Spacing</td>
<td>{plantData.attributes.row_spacing}</td>
<td>{plantData.attributes.row_spacing} cm</td>
</tr>
<tr>
<td>Height</td>
<td>{plantData.attributes.height}</td>
<td>{plantData.attributes.height} cm</td>
</tr>

</tbody>
Expand Down
Loading

0 comments on commit 6d914cc

Please sign in to comment.