Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- .gitattributes +1 -0
- app.py +57 -0
- best_model_InceptionV2.keras +3 -0
- requirements.txt +9 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
best_model_InceptionV2.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
import numpy as np
|
6 |
+
from huggingface_hub import hf_hub_download
|
7 |
+
|
8 |
+
# Download model from Hugging Face Space
|
9 |
+
model_path = hf_hub_download(repo_id="Suphawan/Melanoma", filename="best_model_InceptionV2.keras")
|
10 |
+
|
11 |
+
# Load the trained InceptionV2 model
|
12 |
+
try:
|
13 |
+
model = tf.keras.models.load_model(model_path)
|
14 |
+
print("Model loaded successfully.")
|
15 |
+
except OSError as e:
|
16 |
+
print(f"Error loading model: {e}")
|
17 |
+
model = None # Handle this case appropriately in your code
|
18 |
+
|
19 |
+
# Function for prediction
|
20 |
+
def predict(img):
|
21 |
+
if model is None:
|
22 |
+
return "Model could not be loaded."
|
23 |
+
|
24 |
+
try:
|
25 |
+
img_resized = img.resize((224, 224)) # Resize image to the target size
|
26 |
+
img_array = image.img_to_array(img_resized) # Convert image to array
|
27 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
28 |
+
img_array = preprocess_input(img_array) # Preprocess image according to model requirements
|
29 |
+
|
30 |
+
predictions = model.predict(img_array)
|
31 |
+
class_idx = np.argmax(predictions, axis=1)[0]
|
32 |
+
class_labels = ['Benign', 'Malignant'] # Update according to your class labels
|
33 |
+
class_label = class_labels[class_idx]
|
34 |
+
confidence = float(predictions[0][class_idx])
|
35 |
+
|
36 |
+
return f"Class: {class_label}, Confidence: {confidence:.2f}"
|
37 |
+
except Exception as e:
|
38 |
+
return f"Error: {str(e)}"
|
39 |
+
|
40 |
+
# Define the Gradio app
|
41 |
+
with gr.Blocks() as demo:
|
42 |
+
gr.Markdown("Image Classification with InceptionV2")
|
43 |
+
|
44 |
+
with gr.Row():
|
45 |
+
with gr.Column():
|
46 |
+
classify_input = gr.Image(type="pil", label="Upload an Image")
|
47 |
+
classify_button = gr.Button("Classify!")
|
48 |
+
with gr.Column():
|
49 |
+
classify_output = gr.Textbox(label="Classification Result")
|
50 |
+
|
51 |
+
classify_button.click(
|
52 |
+
predict,
|
53 |
+
inputs=[classify_input],
|
54 |
+
outputs=[classify_output]
|
55 |
+
)
|
56 |
+
|
57 |
+
demo.launch(debug=True)
|
best_model_InceptionV2.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dbf8d3154db9acd877f922cfa6f0f425c552972c1a5c62f93b708ffa7db114ef
|
3 |
+
size 656891655
|
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
|