File size: 1,755 Bytes
aa5b7bd
 
25db719
aa5b7bd
 
 
e71d77f
f469d75
aa5b7bd
25db719
 
 
6df9d56
aa5b7bd
6df9d56
 
 
 
b6a5415
 
ca860a0
 
b6a5415
ca860a0
b6a5415
6df9d56
b6a5415
 
 
 
8aebf88
b6a5415
 
 
6df9d56
b6a5415
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
import tensorflow as tf
from tensorflow.keras.applications.inception_v3 import preprocess_input
from tensorflow.keras.preprocessing import image
import numpy as np

# โหลดโมเดล InceptionV3
model = tf.keras.models.load_model("Inception_V3.h5")

# สมมติว่ามีชื่อคลาสแบบกำหนดเอง
class_names = ["Benign", "Malignant"]  # ปรับชื่อคลาสตามที่คุณฝึกโมเดล

# ฟังก์ชันสำหรับการพยากรณ์
def predict(img):
    img = img.resize((224, 224))  # ปรับขนาดรูปภาพ
    img_array = image.img_to_array(img)  # แปลงรูปภาพเป็นอาร์เรย์
    img_array = np.expand_dims(img_array, axis=0)  # เพิ่มมิติแบทช์
    img_array = preprocess_input(img_array)  # เตรียมรูปภาพให้สอดคล้องกับความต้องการของโมเดล

    predictions = model.predict(img_array)
    predictions = predictions[0]  # เอาค่าผลลัพธ์ของ batch เดียว
    confidence_dict = {class_names[i]: float(predictions[i]) for i in range(len(class_names))}

    return confidence_dict

# สร้าง Gradio Interface
interface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil", label="Upload an Image"),
    outputs=gr.Label(num_top_classes=2, label="Predicted Class"),
    title="Melanoma Classification with InceptionV2",
    description="Upload an image to classify it into one of the classes."
)

# เปิดใช้งานอินเตอร์เฟส
interface.launch()