Spaces:
Running
Running
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import tensorflow as tf
|
4 |
+
from tensorflow.keras.preprocessing import image
|
5 |
+
|
6 |
+
# 모델 로드 (파일명 수정)
|
7 |
+
model = tf.keras.models.load_model("cell_organelle_classifier.keras")
|
8 |
+
|
9 |
+
# 모델의 class_indices 순서에 맞춘 리스트 (오타 수정 포함)
|
10 |
+
class_names = ['class_ER', 'class_chloroplast', 'class_golgi', 'class_mitochondria']
|
11 |
+
|
12 |
+
# 한글 라벨 매핑
|
13 |
+
kor_label_map = {
|
14 |
+
'class_ER': '소포체',
|
15 |
+
'class_chloroplast': '엽록체',
|
16 |
+
'class_golgi': '골지체',
|
17 |
+
'class_mitochondria': '미토콘드리아'
|
18 |
+
}
|
19 |
+
|
20 |
+
# 관련 기사 링크 (클래스명 키도 수정)
|
21 |
+
related_links = {
|
22 |
+
'class_mitochondria': [
|
23 |
+
"https://biz.chosun.com/science-chosun/medicine-health/2025/06/26/LWAWZ4KCDFB4NHXRPNSXZO4BZ4/",
|
24 |
+
"https://www.joongang.co.kr/article/25326557"
|
25 |
+
],
|
26 |
+
'class_ER': [
|
27 |
+
"https://www.snu.ac.kr/research/highlights?md=v&bbsidx=155485",
|
28 |
+
"https://m.dongascience.com/news.php?idx=68985"
|
29 |
+
],
|
30 |
+
'class_golgi': [
|
31 |
+
"https://www.chosun.com/economy/science/2024/07/16/YS7Q7BVSM7G5H7SSPUPFSTWH2I/",
|
32 |
+
"https://www.snu.ac.kr/snunow/press?md=v&bbsidx=149578"
|
33 |
+
],
|
34 |
+
'class_chloroplast': [
|
35 |
+
"https://www.fnewstv.com/news/newsview.php?ncode=1065602102008791&dt=m",
|
36 |
+
"https://www.hani.co.kr/arti/opinion/column/1205729.html"
|
37 |
+
]
|
38 |
+
}
|
39 |
+
|
40 |
+
def classify_image(img):
|
41 |
+
img = img.resize((224, 224))
|
42 |
+
img_array = image.img_to_array(img) / 255.0
|
43 |
+
img_array = np.expand_dims(img_array, axis=0)
|
44 |
+
pred = model.predict(img_array)
|
45 |
+
pred_class = np.argmax(pred[0])
|
46 |
+
pred_label = class_names[pred_class]
|
47 |
+
pred_label_kor = kor_label_map.get(pred_label, pred_label)
|
48 |
+
confidence = pred[0][pred_class] * 100
|
49 |
+
links = related_links[pred_label]
|
50 |
+
|
51 |
+
result = f"🔬 예측 결과: {pred_label_kor} ({confidence:.2f}%)\n\n🔗 관련 기사:\n" + "\n".join(links)
|
52 |
+
return result
|
53 |
+
|
54 |
+
demo = gr.Interface(
|
55 |
+
fn=classify_image,
|
56 |
+
inputs=gr.Image(type="pil"),
|
57 |
+
outputs="text",
|
58 |
+
title="세포소기관 분류기🔬 | 엽록체, 미토콘드리아, 소포체, 골지체 분류",
|
59 |
+
description="이미지를 업로드하면 어떤 세포소기관인지 분류하고 관련 기사를 보여줍니다."
|
60 |
+
)
|
61 |
+
|
62 |
+
demo.launch()
|