Melanoma-2 / app.py
Suphawan's picture
Upload 3 files
e71d77f verified
raw
history blame
1.59 kB
import gradio as gr
import tensorflow as tf
from tensorflow.keras.applications.inception_v3 import preprocess_input # ใช้ฟังก์ชันที่เหมาะสมกับ InceptionV3
from tensorflow.keras.preprocessing import image
import numpy as np
# โหลดโมเดล InceptionV3
model = tf.keras.models.load_model("Inception_V3.h5")
# ฟังก์ชันสำหรับการพยากรณ์
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)
class_idx = np.argmax(predictions, axis=1)[0]
class_label = list(train_generator.class_indices.keys())[class_idx]
confidence = predictions[0][class_idx]
return {class_label: confidence}
# สร้าง 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="Image Classification with InceptionV3",
description="Upload an image to classify it into one of the classes."
)
# เปิดใช้งานอินเตอร์เฟส
interface.launch()