Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ model_paths = {
|
|
25 |
# ฟังก์ชันเตรียมข้อมูลภาพ (และคืนภาพที่ resize แล้ว)
|
26 |
def resize_image(image):
|
27 |
image = image.resize(IMG_SIZE) # Resize เป็น 224x224
|
28 |
-
return image # คืนภาพเพื่อแสดงต่อ
|
29 |
|
30 |
# ฟังก์ชันทำนาย โดยใช้ภาพที่ resize แล้ว
|
31 |
def predict_with_model(resized_image, model_name):
|
@@ -45,28 +45,27 @@ def predict_with_model(resized_image, model_name):
|
|
45 |
result_text = f"\n\n🧠 Prediction Result\n---------------------------\nClass: {class_name}\nConfidence: {confidence}%"
|
46 |
return result_text
|
47 |
|
48 |
-
# สร้าง Gradio
|
49 |
with gr.Blocks() as demo:
|
50 |
gr.Markdown("# 🧠 Stroke Face Classification App")
|
51 |
-
gr.Markdown("Upload a face image. The image will be resized to 224x224
|
52 |
|
53 |
with gr.Row():
|
54 |
with gr.Column():
|
55 |
-
image_input = gr.Image(type="pil", label="🖼️ Upload Face Image")
|
56 |
model_selector = gr.Dropdown(choices=["Custom CNN", "VGG16", "ResNet50"], label="📊 Select Model to Classify")
|
57 |
predict_button = gr.Button("🚀 Predict Stroke")
|
58 |
|
59 |
with gr.Column():
|
60 |
-
resized_image_output = gr.Image(label="🖼️ Resized Image (224x224)")
|
61 |
output_text = gr.Textbox(label="📝 Prediction Output", lines=5)
|
62 |
|
63 |
-
# เมื่ออัปโหลดรูปแล้ว resize
|
64 |
-
image_input.
|
65 |
|
66 |
# เมื่อกดปุ่ม Predict ใช้ภาพที่ resize แล้วไปทำนาย
|
67 |
predict_button.click(
|
68 |
predict_with_model,
|
69 |
-
inputs=[
|
70 |
outputs=output_text
|
71 |
)
|
72 |
|
|
|
25 |
# ฟังก์ชันเตรียมข้อมูลภาพ (และคืนภาพที่ resize แล้ว)
|
26 |
def resize_image(image):
|
27 |
image = image.resize(IMG_SIZE) # Resize เป็น 224x224
|
28 |
+
return image # คืนภาพเพื่อแสดงต่อ (ช่องเดียวกัน)
|
29 |
|
30 |
# ฟังก์ชันทำนาย โดยใช้ภาพที่ resize แล้ว
|
31 |
def predict_with_model(resized_image, model_name):
|
|
|
45 |
result_text = f"\n\n🧠 Prediction Result\n---------------------------\nClass: {class_name}\nConfidence: {confidence}%"
|
46 |
return result_text
|
47 |
|
48 |
+
# สร้าง Gradio Interface แบบไม่มีช่องแยก
|
49 |
with gr.Blocks() as demo:
|
50 |
gr.Markdown("# 🧠 Stroke Face Classification App")
|
51 |
+
gr.Markdown("Upload a face image. The image will be automatically resized to 224x224 and shown here. Then, select a model to classify.")
|
52 |
|
53 |
with gr.Row():
|
54 |
with gr.Column():
|
55 |
+
image_input = gr.Image(type="pil", label="🖼️ Upload & Auto Resize Face Image (224x224)")
|
56 |
model_selector = gr.Dropdown(choices=["Custom CNN", "VGG16", "ResNet50"], label="📊 Select Model to Classify")
|
57 |
predict_button = gr.Button("🚀 Predict Stroke")
|
58 |
|
59 |
with gr.Column():
|
|
|
60 |
output_text = gr.Textbox(label="📝 Prediction Output", lines=5)
|
61 |
|
62 |
+
# เมื่ออัปโหลดรูปแล้ว resize และแสดงแทนที่เดิมทันที
|
63 |
+
image_input.upload(resize_image, inputs=image_input, outputs=image_input)
|
64 |
|
65 |
# เมื่อกดปุ่ม Predict ใช้ภาพที่ resize แล้วไปทำนาย
|
66 |
predict_button.click(
|
67 |
predict_with_model,
|
68 |
+
inputs=[image_input, model_selector],
|
69 |
outputs=output_text
|
70 |
)
|
71 |
|