Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Inception_V3.h5 +3 -0
- app.py +38 -0
- requirements.txt +10 -0
Inception_V3.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6470641316e4c8bdd606e155460d443db7330cae05626623183145fd3f28f319
|
| 3 |
+
size 98695104
|
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from tensorflow.keras.applications.inception_v3 import preprocess_input
|
| 5 |
+
from tensorflow.keras.preprocessing import image
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
# ตั้งค่า logging
|
| 9 |
+
logging.basicConfig(filename="gradio_usage.log", level=logging.INFO)
|
| 10 |
+
|
| 11 |
+
# โหลดโมเดล InceptionV3
|
| 12 |
+
model = tf.keras.models.load_model("Inception_V3.h5")
|
| 13 |
+
|
| 14 |
+
class_names = ["Benign", "Malignant"]
|
| 15 |
+
|
| 16 |
+
def predict(img):
|
| 17 |
+
logging.info("Predict function called.")
|
| 18 |
+
img = img.resize((224, 224))
|
| 19 |
+
img_array = image.img_to_array(img)
|
| 20 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 21 |
+
img_array = preprocess_input(img_array)
|
| 22 |
+
|
| 23 |
+
predictions = model.predict(img_array)
|
| 24 |
+
predictions = predictions[0]
|
| 25 |
+
confidence_dict = {class_names[i]: float(predictions[i]) for i in range(len(class_names))}
|
| 26 |
+
|
| 27 |
+
logging.info(f"Prediction result: {confidence_dict}")
|
| 28 |
+
return confidence_dict
|
| 29 |
+
|
| 30 |
+
interface = gr.Interface(
|
| 31 |
+
fn=predict,
|
| 32 |
+
inputs=gr.Image(type="pil", label="Upload an Image"),
|
| 33 |
+
outputs=gr.Label(num_top_classes=2, label="Predicted Class"),
|
| 34 |
+
title="Melanoma Classification with InceptionV2",
|
| 35 |
+
description="Upload an image to classify it into one of the classes."
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow==2.17.0
|
| 2 |
+
numpy>=1.23.5, <2.0.0
|
| 3 |
+
Pillow==9.2.0
|
| 4 |
+
gradio==3.0.7
|
| 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
|
| 10 |
+
ml-dtypes<0.5.0,>=0.3.1
|