Noeies commited on
Commit
349c7ab
·
verified ·
1 Parent(s): 0992983

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # โหลดโมเดลที่เทรนมาแล้ว
7
+ model_name = "aryan1107/MedMNIST-v2"
8
+ processor = AutoImageProcessor.from_pretrained(model_name)
9
+ model = AutoModelForImageClassification.from_pretrained(model_name)
10
+
11
+ # ฟังก์ชันวิเคราะห์ภาพ
12
+ def predict(image):
13
+ inputs = processor(images=image, return_tensors="pt")
14
+ with torch.no_grad():
15
+ outputs = model(**inputs)
16
+ probs = torch.nn.functional.softmax(outputs.logits, dim=1)
17
+ pred_id = probs.argmax().item()
18
+ label = model.config.id2label[pred_id]
19
+ return f"🩻 อวัยวะที่ตรวจพบ: {label}"
20
+
21
+ # อินเตอร์เฟซ
22
+ iface = gr.Interface(
23
+ fn=predict,
24
+ inputs=gr.Image(type="pil"),
25
+ outputs="text",
26
+ title="🧠 AI ตรวจจับอวัยวะจากภาพ",
27
+ description="อัปโหลดภาพทางการแพทย์ เช่น ภาพเอกซเรย์ หรือ MRI แล้วให้ AI ทายว่าเป็นอวัยวะอะไร"
28
+ )
29
+
30
+ iface.launch()