-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00b9382
commit 6d914cc
Showing
15 changed files
with
544 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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 |
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,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 |
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
Oops, something went wrong.