Delete app.py
Browse files
app.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import torch
|
| 5 |
-
|
| 6 |
-
# ใช้โมเดลที่เทรนไว้แล้ว (จำแนกอวัยวะจากภาพ)
|
| 7 |
-
model_name = "akhaliq/organ-classifier-vit" # ตัวนี้มีใน Hugging Face
|
| 8 |
-
|
| 9 |
-
# โหลดตัวประมวลผลและโมเดล
|
| 10 |
-
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 11 |
-
model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 12 |
-
|
| 13 |
-
# ฟังก์ชันแปลผลภาพ
|
| 14 |
-
def classify_organ(image):
|
| 15 |
-
image = Image.fromarray(image)
|
| 16 |
-
inputs = processor(images=image, return_tensors="pt")
|
| 17 |
-
with torch.no_grad():
|
| 18 |
-
outputs = model(**inputs)
|
| 19 |
-
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 20 |
-
predicted_class = probs.argmax().item()
|
| 21 |
-
label = model.config.id2label[predicted_class]
|
| 22 |
-
confidence = probs[0][predicted_class].item()
|
| 23 |
-
return {label: round(confidence, 3)}
|
| 24 |
-
|
| 25 |
-
# สร้าง UI ด้วย Gradio
|
| 26 |
-
app = gr.Interface(
|
| 27 |
-
fn=classify_organ,
|
| 28 |
-
inputs=gr.Image(type="numpy", label="อัปโหลดภาพอวัยวะ"),
|
| 29 |
-
outputs=gr.Label(num_top_classes=3, label="ผลลัพธ์จาก AI"),
|
| 30 |
-
title="🧠 ตัวจำแนกอวัยวะด้วย AI",
|
| 31 |
-
description="อัปโหลดภาพ (เช่น หัวใจ ปอด สมอง ฯลฯ) แล้วให้ AI วิเคราะห์ว่าเป็นอวัยวะอะไร",
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
if __name__ == "__main__":
|
| 35 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|