Horus7 commited on
Commit
0480888
·
1 Parent(s): 60e1847

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import os
5
+ import tensorflow as tf
6
+ import numpy as np
7
+ from keras.models import load_model
8
+ from tensorflow.keras.utils import load_img
9
+
10
+ # Charger le modèle
11
+
12
+ model = load_model('model_multi.h5')
13
+
14
+
15
+ def format_decimal(value):
16
+ decimal_value = format(value, ".2f")
17
+ return decimal_value
18
+
19
+ def detect(img):
20
+ img = np.expand_dims(img, axis=0)
21
+ img = img/255
22
+ prediction = model.predict(img)[0]
23
+ # if prediction[0] <= 0.80:
24
+ # return "Pneumonia Detected!"
25
+
26
+ # return "Pneumonia Not Detected!"
27
+ if format_decimal(prediction[0]) >= "0.5":
28
+ return "Risque d'infection bactérienne"
29
+ if format_decimal(prediction[1]) >= "0.5":
30
+ return "Poumon sain"
31
+ if format_decimal(prediction[2]) >= "0.5":
32
+ return "Risque d'infection biologique"
33
+
34
+
35
+ # result = detect(img)
36
+ # print(result)
37
+ os.system("tar -zxvf examples.tar.gz")
38
+ examples = ['examples/n1.jpeg', 'examples/n2.jpeg', 'examples/n3.jpeg', 'examples/n4.jpeg', 'examples/n5.jpeg',
39
+ 'examples/n6.jpeg', 'examples/n7.jpeg', 'examples/n8.jpeg', 'examples/p6.jpeg', 'examples/p7.jpeg',]
40
+
41
+ input = gr.inputs.Image(shape=(100,100))
42
+
43
+
44
+
45
+ title = "PneumoDetect: Pneumonia Detection from Chest X-Rays"
46
+
47
+ iface = gr.Interface(fn=detect, inputs=input, outputs="text",examples = examples, examples_per_page=20, title=title)
48
+ iface.launch(inline=False)