Switch to unified view

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