shanmukavenkat commited on
Commit
cffd0b8
·
1 Parent(s): 14166ca

lungDisease

Browse files
README.md CHANGED
@@ -1,12 +1,14 @@
1
  ---
2
- title: LungDisease
3
- emoji: 🔥
4
- colorFrom: pink
5
- colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.23.1
8
  app_file: app.py
9
  pinned: false
 
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: PULMONET
3
+ emoji: 🐢
4
+ colorFrom: purple
5
+ colorTo: gray
6
  sdk: gradio
7
  sdk_version: 5.23.1
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
+ short_description: A model to predict lung ill on x-ray images
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load model
7
+ print("Loading model...")
8
+ modelo = tf.keras.models.load_model("modelo_multilabel_mejorado3.h5")
9
+ print("Model loaded.")
10
+
11
+ # Model classes
12
+ target_classes = ['Atelectasis', 'Effusion', 'Infiltration', 'Nodule', 'Pneumothorax']
13
+ UMBRAL_PROBABILIDAD = 0.3 # Minimum 30% to consider a disease relevant
14
+
15
+ def predecir(img):
16
+ img = img.resize((224, 224))
17
+ img = np.array(img) / 255.0
18
+ img = np.expand_dims(img, axis=0)
19
+ pred = modelo.predict(img)[0]
20
+ resultados = [(target_classes[i], prob) for i, prob in enumerate(pred)]
21
+ resultados = [(enf, p) for enf, p in resultados if p >= UMBRAL_PROBABILIDAD]
22
+ resultados.sort(key=lambda x: x[1], reverse=True)
23
+ if not resultados:
24
+ return "ERROR "
25
+ salida = "\n".join([f"{enf}: {p*100:.2f}%" for enf, p in resultados[:2]])
26
+ return salida
27
+
28
+ # Custom CSS to style the background and iframe lines
29
+ custom_css = """
30
+ body {
31
+ background-color: #efefef;
32
+ }
33
+ iframe {
34
+ border-top: 4px solid #000;
35
+ border-bottom: 4px solid #000;
36
+ }
37
+ """
38
+
39
+ # Gradio Interface
40
+ demo = gr.Interface(
41
+ fn=predecir,
42
+ inputs=gr.Image(type="pil", label="Sube tu imagen"),
43
+ outputs="text",
44
+ title="Detection of Pulmonary Diseases",
45
+ description="Upload a chest X-ray, and the model will identify possible diseases",
46
+ theme="default",
47
+ css=custom_css
48
+ )
49
+
50
+ # Launch application
51
+ demo.launch(server_name="0.0.0.0", share=True)
modelo_multilabel_mejorado.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0101b97f22bb7d3438a0a2e7999d6ff5a672ff5983717e1b1c9b0e540f85e924
3
+ size 28809976
modelo_multilabel_mejorado3.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4fdbcee3e826028897f2a6cadc28d5082d5acf8a992423d5f6e4018433f2a45
3
+ size 28832096
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow
2
+ numpy
3
+ pillow
4
+ gradio