Skip to content

Commit effc0eb

Browse files
committed
change style
1 parent f6aca2a commit effc0eb

18 files changed

+240
-83
lines changed

back/api/api.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77
from fastapi.middleware.cors import CORSMiddleware
88
from database import Database
99
from utils import recognize_data, split_data
10+
from onnxruntime import InferenceSession
1011

11-
inf = Inference()
12+
print('setup start...')
13+
ort_sess = InferenceSession("./models/vit_model.onnx", providers=['CPUExecutionProvider'])
14+
input_name = ort_sess.get_inputs()[0].name
15+
output_name = ort_sess.get_outputs()[0].name
16+
17+
inf = Inference(ort_sess=ort_sess, input_name=input_name, output_name=output_name)
18+
print('setup ok')
1219
db = Database()
1320

1421
app = FastAPI()
@@ -36,6 +43,20 @@ async def detect_pneumonia(images: List[UploadFile]=File(...)):
3643
pred = list(inf.predict_image())
3744
return pred
3845

46+
@app.post('/prediction_multiple_pneumoniaa', response_model=List[int])
47+
async def detect_pneumonia(images: List[UploadFile]=File(...)):
48+
"""Pneumonia detection on single or multiple images
49+
Args:
50+
images (List[UploadFile], optional): List of images as bytes
51+
Returns:
52+
pred: List corresponding to images diagnostic (0 : no pneumonia, 1 : pneumonia)
53+
"""
54+
images_bytes = []
55+
for image in images :
56+
images_bytes.append(image.file.read())
57+
pred = list(inf.onnx_inferences(images_bytes))
58+
return pred
59+
3960
@app.post('/add_data')
4061
async def add_data(data: Request):
4162
"""Add Data to Postgres Database

back/api/predict.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import joblib
22
import numpy as np
3-
from PIL import Image
43
from io import BytesIO
4+
import onnxruntime
5+
from PIL import Image
56

67

78
class Inference():
89

9-
def __init__(self):
10-
10+
def __init__(self, ort_sess, input_name, output_name):
11+
# self.ort_sess = onnxruntime.InferenceSession("./models/vit_model.onnx", providers=['CPUExecutionProvider'])
12+
# self.input_name = self.ort_sess.get_inputs()[0].name
13+
# self.output_name = self.ort_sess.get_outputs()[0].name
1114
self.model = joblib.load('./models/random_forest_150x150x1.joblib')
15+
self.ort_sess = ort_sess
16+
self.input_name = input_name
17+
self.output_name = output_name
1218

1319
def load_single_image(self, bytes):
1420
"""Load single image with associated bytes
@@ -44,3 +50,20 @@ def load_multiple_img(self, bytes) :
4450

4551
def predict_image(self):
4652
return self.model.predict(self.image)
53+
54+
def load_onnx_image(self, bytes):
55+
decoded = BytesIO(bytes)
56+
image = Image.open(decoded).convert("RGB")
57+
image = image.resize((224, 224), Image.BILINEAR)
58+
img = np.array(image, dtype=np.float32)
59+
img /= 255.0
60+
img = np.transpose(img, (2, 0, 1))
61+
return img
62+
63+
def onnx_inferences(self, bytes):
64+
inputs = np.array([self.load_onnx_image(path) for path in bytes])
65+
outputs = self.ort_sess.run([self.output_name], {self.input_name: inputs})[0]
66+
logits = np.array(outputs)
67+
probabilities = np.exp(logits) / np.sum(np.exp(logits), axis=1, keepdims=True)
68+
predicted_classes = np.argmax(probabilities, axis=1)
69+
return predicted_classes

back/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ uvicorn
66
fastapi
77
psycopg2-binary
88
SQLAlchemy
9-
pandas
9+
pandas
10+
onnxruntime

docker-compose.yml

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
version: "3"
1+
version: '3'
22
services:
3-
43
db:
5-
image: postgres
6-
restart: unless-stopped
7-
container_name: db
8-
environment:
9-
- POSTGRES_USER=postgres
10-
- POSTGRES_PASSWORD=postgres
11-
- POSTGRES_DB=medicalDB
12-
ports:
13-
- '5432:5432'
14-
volumes:
15-
- ./db:/var/lib/postgresql/data
16-
- ./init.sql:/docker-entrypoint-initdb.d/create_tables.sql
4+
image: postgres
5+
restart: unless-stopped
6+
container_name: db
7+
environment:
8+
- POSTGRES_USER=postgres
9+
- POSTGRES_PASSWORD=postgres
10+
- POSTGRES_DB=medicalDB
11+
ports:
12+
- '5432:5432'
13+
volumes:
14+
- ./db:/var/lib/postgresql/data
15+
- ./init.sql:/docker-entrypoint-initdb.d/create_tables.sql
1716

1817
nginx:
1918
restart: unless-stopped
@@ -24,19 +23,19 @@ services:
2423
- backend
2524
- frontend
2625
ports:
27-
- "3000:80"
26+
- '80:80'
2827

2928
frontend:
3029
platform: linux/amd64
3130
restart: unless-stopped
32-
build:
31+
build:
3332
context: ./front
3433
dockerfile: ./Dockerfile
3534

36-
backend :
35+
backend:
3736
platform: linux/amd64
3837
restart: unless-stopped
39-
build:
38+
mem_limit: 4g
39+
build:
4040
context: ./back
4141
dockerfile: ./Dockerfile
42-

front/public/background.webp

315 KB
Binary file not shown.

front/public/background2.png

2.08 MB
Loading

front/public/index.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4+
<style>
5+
body {
6+
background-image: url('/background2.png');
7+
background-size: cover;
8+
background-attachment: fixed;
9+
background-repeat: no-repeat;
10+
}
11+
</style>
412
<meta charset="utf-8" />
5-
<link rel="icon" href="logo.png" />
13+
<link rel="icon" href="logo2.png" />
614
<meta name="viewport" content="width=device-width, initial-scale=1" />
715
<meta name="theme-color" content="#000000" />
816
<meta

front/public/logo2.png

1.31 MB
Loading

front/src/components/about.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ const TitleComponent = () => {
1111
<Stack style={{ height: '100vh', overflow: 'hidden' }}>
1212
<Stack
1313
sx={{
14+
paddingBottom: '10px',
15+
paddingTop: '10px',
16+
paddingLeft: '10px',
17+
paddingRight: '10px',
1418
position: 'absolute',
1519
borderRadius: '10px',
16-
border: 15,
17-
borderColor: '#FFFFFF',
18-
backgroundColor: '#FFFFFF',
20+
borderColor: 'rgb(249,249,249,0.8)',
21+
backgroundColor: 'rgb(249,249,249,0.8)',
1922
top: '50%',
2023
left: '50%',
2124
transform: 'translate(-50%, -50%)',

front/src/components/data.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,21 @@ const Data = () => {
119119
<Stack spacing={5} alignItems="center">
120120
<Stack
121121
spacing={2}
122+
alignItems="center"
122123
sx={{
123124
maxHeight: 700,
124-
backgroundColor: '#FFFFFF',
125+
marginBottom: '10px',
126+
paddingTop: '10px',
127+
paddingLeft: '10px',
128+
paddingRight: '10px',
125129
borderRadius: '10px',
126-
border: 15,
127-
borderColor: '#FFFFFF',
130+
width: '90%',
131+
maxWidth: '1200px',
132+
borderColor: 'rgb(249,249,249,0.8)',
133+
backgroundColor: 'rgb(249,249,249,0.8)',
128134
}}
129135
>
130-
<Stack direction="row" spacing={5}>
136+
<Stack direction="row" spacing={5} justifyContent="center">
131137
<SearchBar
132138
value={searched}
133139
onChange={(searchVal) => requestSearchFilename(searchVal)}
@@ -140,7 +146,10 @@ const Data = () => {
140146
onCancelSearch={() => cancelSearchDoctor()}
141147
placeholder="Filter on a doctor name"
142148
/>
143-
<FormControl variant="standard" sx={{ m: 1, minWidth: 120 }}>
149+
<FormControl
150+
variant="standard"
151+
sx={{ minWidth: 120, backgroundColor: 'white' }}
152+
>
144153
<InputLabel id="select-diagnostic">Diagnostic</InputLabel>
145154
<Select
146155
value={filterDiagnostic}
@@ -172,7 +181,9 @@ const Data = () => {
172181
{filterRows.map((row, idx) => (
173182
<TableRow
174183
key={idx}
175-
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
184+
sx={{
185+
'&:last-child td, &:last-child th': { border: 0 },
186+
}}
176187
>
177188
<TableCell align="center" component="th" scope="row">
178189
{row.filename}
@@ -188,6 +199,7 @@ const Data = () => {
188199
) : (
189200
<div></div>
190201
)}
202+
<br />
191203
</Stack>
192204
</Stack>
193205
</Stack>

front/src/components/home.js

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState, useEffect } from 'react';
2-
import logo from './images/logo.png';
32
import AppBar from '@mui/material/AppBar';
43
import Typography from '@mui/material/Typography';
54
import Stack from '@mui/material/Stack';
@@ -46,29 +45,22 @@ const Home = () => {
4645
<AppBar
4746
position="relative"
4847
color="inherit"
49-
sx={{ width: '60%', borderRadius: '10px' }}
48+
sx={{
49+
width: '60%',
50+
borderRadius: '10px',
51+
backgroundColor: 'rgb(249,249,249,0.8)',
52+
}}
5053
>
5154
<Stack
5255
justifyContent="center"
5356
alignItems="center"
5457
direction="row"
5558
spacing={5}
5659
>
57-
<img
58-
src={logo}
59-
style={{
60-
width: 200,
61-
height: 200,
62-
marginLeft: '1.5rem',
63-
position: 'absolut',
64-
}}
65-
alt="logo"
66-
/>
6760
<Typography
6861
variant="h1"
6962
style={{
70-
background:
71-
'linear-gradient(39deg, rgba(210,191,195,1) 0%, rgba(170,70,86,1) 50%, rgba(116,13,16,1) 100%)',
63+
background: 'black',
7264
webkitBackgroundClip: 'text',
7365
WebkitTextFillColor: 'transparent',
7466
fontFamily: 'skia',
@@ -84,18 +76,17 @@ const Home = () => {
8476
sx={{
8577
marginTop: '2%',
8678
width: '90%',
87-
maxEight: '90%',
79+
maxHeight: '90%',
8880
borderRadius: '10px',
89-
borderColor: '#FFFFFF',
90-
backgroundColor: '#FFFFFF',
81+
borderColor: 'rgb(249,249,249,0.8)',
82+
backgroundColor: 'rgb(249,249,249,0.8)',
9183
}}
9284
>
9385
<Stack alignItems="center" spacing={7}>
9486
<Typography
9587
variant="h2"
9688
style={{
97-
background:
98-
'linear-gradient(39deg, rgba(210,191,195,1) 0%, rgba(170,70,86,1) 50%, rgba(116,13,16,1) 100%)',
89+
background: 'black',
9990
webkitBackgroundClip: 'text',
10091
WebkitTextFillColor: 'transparent',
10192
fontFamily: 'skia',

front/src/components/images/logo2.png

1.31 MB
Loading

front/src/components/navbar.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,31 @@ import Container from 'react-bootstrap/Container';
22
import Nav from 'react-bootstrap/Nav';
33
import Navbar from 'react-bootstrap/Navbar';
44
import { Link } from 'react-router-dom';
5-
import logo from './images/logo.png';
5+
import { Stack, Typography } from '@mui/material';
6+
import HomeIcon from '@mui/icons-material/Home';
67

78
const NavBar = () => {
89
return (
910
<>
10-
<Navbar collapseOnSelect style={{ background: 'white' }} expand="lg">
11+
<Navbar collapseOnSelect style={{ background: '#740d10' }} expand="lg">
1112
<Container>
1213
<Navbar.Brand as={Link} to={'/'}>
13-
<img
14-
src={logo}
15-
style={{
16-
width: 45,
17-
height: 45,
18-
position: 'absolut',
19-
}}
20-
alt="logo"
21-
/>
22-
PneumonIA
14+
<Stack direction="row" alignItems="center" spacing={1}>
15+
<HomeIcon sx={{ color: 'white' }} />
16+
<Typography sx={{ color: 'white' }}>PneumonIA</Typography>
17+
</Stack>
2318
</Navbar.Brand>
2419
<Navbar.Toggle aria-controls="basic-navbar-nav" />
2520

2621
<Navbar.Collapse id="basic-navbar-nav">
2722
<Nav className="me-auto">
28-
<Nav.Link as={Link} to={'/prediction'}>
23+
<Nav.Link as={Link} to={'/prediction'} style={{ color: 'white' }}>
2924
Pneumonia Detection
3025
</Nav.Link>
31-
<Nav.Link as={Link} to={'/data'}>
26+
<Nav.Link as={Link} to={'/data'} style={{ color: 'white' }}>
3227
Database
3328
</Nav.Link>
34-
<Nav.Link as={Link} to={'/about'}>
29+
<Nav.Link as={Link} to={'/about'} style={{ color: 'white' }}>
3530
About
3631
</Nav.Link>
3732
</Nav>

0 commit comments

Comments
 (0)