Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +46 -0
- best_model_InceptionV2.h5 +3 -0
- requirements.txt +9 -0
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.applications.inception_resnet_v2 import preprocess_input
|
| 4 |
+
from tensorflow.keras.preprocessing import image
|
| 5 |
+
from tensorflow.keras.models import load_model
|
| 6 |
+
import numpy as np
|
| 7 |
+
from PIL import Image
|
| 8 |
+
|
| 9 |
+
model = load_model('best_model_InceptionV2.keras')
|
| 10 |
+
|
| 11 |
+
# Function for prediction
|
| 12 |
+
def predict(img):
|
| 13 |
+
try:
|
| 14 |
+
img_resized = img.resize((224, 224)) # Resize image to the target size
|
| 15 |
+
img_array = image.img_to_array(img_resized) # Convert image to array
|
| 16 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
| 17 |
+
img_array = preprocess_input(img_array) # Preprocess image according to model requirements
|
| 18 |
+
|
| 19 |
+
predictions = model.predict(img_array)
|
| 20 |
+
class_idx = np.argmax(predictions, axis=1)[0]
|
| 21 |
+
class_labels = ['Benign', 'Malignant'] # Update according to your class labels
|
| 22 |
+
class_label = class_labels[class_idx]
|
| 23 |
+
confidence = float(predictions[0][class_idx])
|
| 24 |
+
|
| 25 |
+
return f"Class: {class_label}, Confidence: {confidence:.2f}"
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"Error in prediction: {e}"
|
| 28 |
+
|
| 29 |
+
# Define the Gradio app
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("Image Classification with InceptionV2")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
with gr.Column():
|
| 35 |
+
classify_input = gr.Image(type="pil", label="Upload an Image")
|
| 36 |
+
classify_button = gr.Button("Classify!")
|
| 37 |
+
with gr.Column():
|
| 38 |
+
classify_output = gr.Textbox(label="Classification Result")
|
| 39 |
+
|
| 40 |
+
classify_button.click(
|
| 41 |
+
predict,
|
| 42 |
+
inputs=[classify_input],
|
| 43 |
+
outputs=[classify_output]
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
demo.launch()
|
best_model_InceptionV2.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f807bdfaa90db4b1ea74aa60fb3901ffafb2127fc1233d3a22639083fccdf013
|
| 3 |
+
size 656736608
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow==2.11.0
|
| 2 |
+
numpy==1.21.6
|
| 3 |
+
Pillow==9.2.0
|
| 4 |
+
gradio==3.6.0
|
| 5 |
+
httpx==0.21.1
|
| 6 |
+
seaborn==0.11.2
|
| 7 |
+
matplotlib==3.5.1
|
| 8 |
+
scikit-learn==1.1.3
|
| 9 |
+
Cython==0.29.32
|