[69507b]: / app / frontend / src / components / TableRow.js

Download this file

109 lines (96 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
import React,{useEffect,useState} from 'react'
const TableRow = (props) => {
const [image, updateImage] = React.useState("");
//Create new_state Object for Gradcam
const [GradCam, updateGradCam] = React.useState(null);
// {"0":["covid"],"1":["nofinding"],"2":["opacity"]}
const createTag = (tag) =>{
if(tag=="covid"){
return(<span
class="relative inline-block px-3 py-1 font-semibold text-orange-900 leading-tight">
<span aria-hidden
class="absolute inset-0 bg-red-200 opacity-50 rounded-full"></span>
<span class="relative">Suspected Covid</span>
</span>)
}
if(tag=="nofinding"){
return(<span
class="relative inline-block px-3 py-1 font-semibold text-green-900 leading-tight">
<span aria-hidden
class="absolute inset-0 bg-green-200 opacity-50 rounded-full"></span>
<span class="relative">No Findings</span>
</span>)
}
if(tag=="opacity"){
return(<span
class="relative inline-block px-3 py-1 font-semibold text-green-900 leading-tight">
<span aria-hidden
class="absolute inset-0 bg-orange-200 opacity-50 rounded-full"></span>
<span class="relative">Opacity</span>
</span>)
}
}
useEffect(() => {
// Create an scoped async function in the hook
async function getImage() {
fetch(`http://backend:5000/uploads/${props.filename}`)
.then(response => response.blob())
.then(blob => updateImage(URL.createObjectURL(blob)))
}
//Modify this to the api endpoint for the gradcam
//Only Image is called by default
getImage();
// if(props.prediction!="nofinding"){
// updateGradCam("NA")
// }else{
// getGradcam();
// }
}, []);
async function getGradcam() {
fetch(`http://backend:5000/gradcam/${props.filename}`)
.then(response => response.blob())
.then(blob => updateGradCam(URL.createObjectURL(blob)))
}
const renderGradcam = (GradCam) => {
if(GradCam === null){
return (
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick = {()=>getGradcam()}>
Generate Gradcam
</button>
)
}
else{
return <img style = {{minWidth:"130px",maxWidth:"130px"}} alt="home" src={ GradCam }></img>
}
}
const Tag = createTag(props.prediction)
return (
<tr>
<td class="px-5 py-5 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap">{props.filename}</p>
</td>
<td class="px-5 py-5 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap">{props.patientId}</p>
</td>
<td class="px-5 py-5 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap">{props.sex}</p>
</td>
<td class="px-5 py-5 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap">{props.Age}</p>
</td>
<td class="px-5 py-5 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap">{props.view}</p>
</td>
<td class="px-5 py-5 bg-white text-sm">
<p class="text-gray-900 whitespace-no-wrap">{Tag}</p>
</td>
<td class="px-5 py-5 bg-white text-sm">
{ image && <img style = {{minWidth:"130px",maxWidth:"130px"}} alt="home" src={ image }></img> }
</td>
<td class="px-5 py-5 bg-white text-sm">
{props.prediction === "nofinding" ? "No Gradcam Avaliable" : renderGradcam(GradCam)}
</td>
</tr>
)
}
export default TableRow;