Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,18 @@
|
|
| 1 |
-
# Disable GPU to avoid CUDA errors on Hugging Face Spaces
|
| 2 |
-
import os
|
| 3 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
| 4 |
-
|
| 5 |
-
# Install dependencies
|
| 6 |
from huggingface_hub import hf_hub_download
|
| 7 |
import tensorflow as tf
|
| 8 |
import gradio as gr
|
| 9 |
import numpy as np
|
| 10 |
from PIL import Image
|
|
|
|
| 11 |
|
| 12 |
-
#
|
|
|
|
|
|
|
|
|
|
| 13 |
model_path = hf_hub_download(repo_id="Owos/tb-classifier", filename="tb_model.h5")
|
| 14 |
model = tf.keras.models.load_model(model_path)
|
| 15 |
|
| 16 |
-
#
|
| 17 |
def predict_tb(img: Image.Image):
|
| 18 |
try:
|
| 19 |
image = img.convert("RGB").resize((224, 224))
|
|
@@ -26,3 +25,14 @@ def predict_tb(img: Image.Image):
|
|
| 26 |
except Exception as e:
|
| 27 |
return f"❌ Error during prediction: {str(e)}"
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from huggingface_hub import hf_hub_download
|
| 2 |
import tensorflow as tf
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
+
# Disable GPU usage
|
| 9 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
| 10 |
+
|
| 11 |
+
# Download and load model
|
| 12 |
model_path = hf_hub_download(repo_id="Owos/tb-classifier", filename="tb_model.h5")
|
| 13 |
model = tf.keras.models.load_model(model_path)
|
| 14 |
|
| 15 |
+
# Inference function
|
| 16 |
def predict_tb(img: Image.Image):
|
| 17 |
try:
|
| 18 |
image = img.convert("RGB").resize((224, 224))
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
return f"❌ Error during prediction: {str(e)}"
|
| 27 |
|
| 28 |
+
# Gradio UI
|
| 29 |
+
iface = gr.Interface(
|
| 30 |
+
fn=predict_tb,
|
| 31 |
+
inputs=gr.Image(type="pil", label="Upload Chest X-ray Image"),
|
| 32 |
+
outputs="text",
|
| 33 |
+
title="🩻 Tuberculosis Detection from Chest X-ray",
|
| 34 |
+
description="Upload a chest X-ray to detect signs of Tuberculosis using an AI model (ResNet50). For educational & demo use only."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Launch the app
|
| 38 |
+
iface.launch()
|