Downloads · 30 days
0
almohab/mobilenet_tb_model
mobilenet_tb_model is a machine learning model from almohab. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
import gradio as gr import numpy as np import tensorflow as tf from tensorflow.keras.models import loadmodel from tensorflow.keras.preprocessing import image import requests from io import BytesIO
Downloads · 30 days
0
Access
Public
Updated Mar 25, 2025
Repo size
18.9 MB
Likes
0
Public
Click a slice to open those files.
.h518.9 MB · 100%
From the Hugging Face model README
import gradio as gr import numpy as np import tensorflow as tf from tensorflow.keras.models import load_model from tensorflow.keras.preprocessing import image import requests from io import BytesIO
model_url = "https://huggingface.co/almohab/mobilenet_tb_model/resolve/main/mobilenet_tb_model.h5" model_path = "mobilenet_tb_model.h5"
try: open(model_path) except: print("Downloading model...") response = requests.get(model_url) with open(model_path, "wb") as f: f.write(response.content)
model = load_model(model_path) labels = ["Normal", "Tuberculosis"] # Adjust based on your classes
def predict_tb(img): img = img.resize((224, 224)) # Resize image to match MobileNet input size img = image.img_to_array(img) img = np.expand_dims(img, axis=0) img = img / 255.0 # Normalize
prediction = model.predict(img)
result = labels[int(prediction[0] > 0.5)] # Assume binary classification
return f"Prediction: {result}"
interface = gr.Interface( fn=predict_tb, inputs=gr.Image(type="pil"), outputs="text", title="Tuberculosis Detection API", description="Upload a chest X-ray image to check if it is normal or tuberculosis." )
interface.launch()