Noeies commited on
Commit
fc8a179
·
verified ·
1 Parent(s): f945346

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -35
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 = "mohamedali12/BodyOrgansClassification"
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
- # ส่วนติดต่อ 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()