|
import os |
|
import tensorflow as tf |
|
from tensorflow.keras.preprocessing.image import load_img, img_to_array |
|
import numpy as np |
|
import gradio as gr |
|
|
|
|
|
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" |
|
|
|
|
|
model = tf.keras.models.load_model("maheshbabu.h5") |
|
|
|
|
|
classes = ["Normal","Cancerous"] |
|
|
|
|
|
def predict(image): |
|
try: |
|
|
|
img = load_img(image, target_size=(224, 224)) |
|
img_array = img_to_array(img) / 255.0 |
|
img_array = np.expand_dims(img_array, axis=0) |
|
|
|
|
|
predictions = model.predict(img_array) |
|
class_idx = np.argmax(predictions[0]) |
|
confidence = predictions[0][class_idx] |
|
|
|
return f"{classes[class_idx]} ({confidence:.2f})" |
|
except Exception as e: |
|
return f"Error processing image: {str(e)}" |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(type="filepath"), |
|
outputs="label", |
|
title="Blood Cancer Detection", |
|
description="Upload an image to detect whether it is Normal or Cancerous." |
|
) |
|
|
|
if __name__ == "__main__": |
|
interface.launch(server_port=7860, server_name="0.0.0.0", share=True) |