Spaces:
Sleeping
Sleeping
chengwang96 commited on
Commit ·
1db65f3
1
Parent(s): 41edbc8
track png with git lfs
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- .gitignore +1 -0
- app.py +99 -45
- f1_input/1.png +3 -0
- f1_input/10.png +3 -0
- f1_input/11.png +3 -0
- f1_input/12.png +3 -0
- f1_input/13.png +3 -0
- f1_input/14.png +3 -0
- f1_input/15.png +3 -0
- f1_input/16.png +3 -0
- f1_input/17.png +3 -0
- f1_input/18.png +3 -0
- f1_input/19.png +3 -0
- f1_input/2.png +3 -0
- f1_input/20.png +3 -0
- f1_input/21.png +3 -0
- f1_input/22.png +3 -0
- f1_input/23.png +3 -0
- f1_input/24.png +3 -0
- f1_input/25.png +3 -0
- f1_input/26.png +3 -0
- f1_input/27.png +3 -0
- f1_input/28.png +3 -0
- f1_input/29.png +3 -0
- f1_input/3.png +3 -0
- f1_input/30.png +3 -0
- f1_input/4.png +3 -0
- f1_input/5.png +3 -0
- f1_input/6.png +3 -0
- f1_input/7.png +3 -0
- f1_input/8.png +3 -0
- f1_input/9.png +3 -0
- f1_output/1.png +3 -0
- f1_output/10.png +3 -0
- f1_output/11.png +3 -0
- f1_output/12.png +3 -0
- f1_output/13.png +3 -0
- f1_output/14.png +3 -0
- f1_output/15.png +3 -0
- f1_output/16.png +3 -0
- f1_output/17.png +3 -0
- f1_output/18.png +3 -0
- f1_output/19.png +3 -0
- f1_output/2.png +3 -0
- f1_output/20.png +3 -0
- f1_output/21.png +3 -0
- f1_output/22.png +3 -0
- f1_output/23.png +3 -0
- f1_output/24.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.DS_Store
|
app.py
CHANGED
|
@@ -1,57 +1,111 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
with gr.Row():
|
| 32 |
-
# 图像增强模块
|
| 33 |
with gr.Column():
|
| 34 |
gr.Markdown("### 图像增强模块")
|
| 35 |
-
|
| 36 |
-
|
| 37 |
enhance_btn = gr.Button("增强图片")
|
| 38 |
-
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
with gr.Row():
|
| 41 |
-
#
|
| 42 |
with gr.Column():
|
| 43 |
-
gr.Markdown("###
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
with gr.Column():
|
| 51 |
-
gr.Markdown("###
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import os
|
| 4 |
+
import random
|
| 5 |
+
|
| 6 |
+
# ========== 配置图片路径 ==========
|
| 7 |
+
# 图像增强
|
| 8 |
+
ENHANCE_INPUT_DIR = "f1_input"
|
| 9 |
+
ENHANCE_OUTPUT_DIR = "f1_output"
|
| 10 |
+
ENHANCE_IMG_NAMES = [f"{i}.png" for i in range(1, 613)] # 1.png ~ 612.png
|
| 11 |
+
|
| 12 |
+
# 分割
|
| 13 |
+
SEG_INPUT_DIR = "seg_input"
|
| 14 |
+
SEG_OUTPUT_DIR = "seg_output"
|
| 15 |
+
SEG_IMG_NAMES = [f"{i}.png" for i in range(1, 6)] # 1.png ~ 5.png
|
| 16 |
+
|
| 17 |
+
# 诊断
|
| 18 |
+
DIAG_INPUT_DIR = "diag_input"
|
| 19 |
+
DIAG_IMG_NAMES = [f"{i}.png" for i in range(1, 6)] # 1.png ~ 5.png
|
| 20 |
+
|
| 21 |
+
# Kvasir 类别
|
| 22 |
+
KVASIR_CLASSES = [
|
| 23 |
+
"正常粘膜 (normal-z-line)",
|
| 24 |
+
"食管静脉曲张 (esophagitis)",
|
| 25 |
+
"食管腺癌 (barretts)",
|
| 26 |
+
"息肉 (polyps)",
|
| 27 |
+
"溃疡 (ulcerative-colitis)",
|
| 28 |
+
"糜烂 (dyed-lifted-polyps)",
|
| 29 |
+
"出血 (dyed-resection-margins)",
|
| 30 |
+
"炎症 (bbps-0-1)",
|
| 31 |
+
"直肠癌 (bbps-2-3)"
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
# ========== 功能函数 ==========
|
| 35 |
+
def open_img(img_path):
|
| 36 |
+
if not os.path.exists(img_path):
|
| 37 |
+
# 返回一张空白图片
|
| 38 |
+
return Image.new("RGB", (256, 256), (200, 200, 200))
|
| 39 |
+
return Image.open(img_path)
|
| 40 |
+
|
| 41 |
+
# 图像增强模块
|
| 42 |
+
def show_enhance_input(img_name):
|
| 43 |
+
path = os.path.join(ENHANCE_INPUT_DIR, img_name)
|
| 44 |
+
return open_img(path)
|
| 45 |
+
|
| 46 |
+
def enhance_demo(img_name):
|
| 47 |
+
path = os.path.join(ENHANCE_OUTPUT_DIR, img_name)
|
| 48 |
+
return open_img(path)
|
| 49 |
+
|
| 50 |
+
# 图像分割模块
|
| 51 |
+
def show_seg_input(img_name):
|
| 52 |
+
path = os.path.join(SEG_INPUT_DIR, img_name)
|
| 53 |
+
return open_img(path)
|
| 54 |
+
|
| 55 |
+
def segment_demo(img_name):
|
| 56 |
+
path = os.path.join(SEG_OUTPUT_DIR, img_name)
|
| 57 |
+
return open_img(path)
|
| 58 |
+
|
| 59 |
+
# 疾病诊断模块
|
| 60 |
+
def show_diag_input(img_name):
|
| 61 |
+
path = os.path.join(DIAG_INPUT_DIR, img_name)
|
| 62 |
+
return open_img(path)
|
| 63 |
+
|
| 64 |
+
def diagnose_demo(img_name):
|
| 65 |
+
pred = random.choice(KVASIR_CLASSES)
|
| 66 |
+
conf = round(random.uniform(0.85, 0.99), 2)
|
| 67 |
+
return f"诊断结果:{pred}\n置信度:{conf}"
|
| 68 |
+
|
| 69 |
+
# ========== Gradio 布局 ==========
|
| 70 |
+
with gr.Blocks(title="AI内窥镜影像辅助分析系统") as demo:
|
| 71 |
+
gr.Markdown("## AI内窥镜影像辅助分析系统")
|
| 72 |
+
|
| 73 |
+
# 上方:图像增强模块
|
| 74 |
with gr.Row():
|
|
|
|
| 75 |
with gr.Column():
|
| 76 |
gr.Markdown("### 图像增强模块")
|
| 77 |
+
enhance_select = gr.Dropdown(choices=ENHANCE_IMG_NAMES, value=ENHANCE_IMG_NAMES[0], label="选择样例图片", filterable=True)
|
| 78 |
+
enhance_input_img = gr.Image(label="原始图片", interactive=False)
|
| 79 |
enhance_btn = gr.Button("增强图片")
|
| 80 |
+
enhance_output_img = gr.Image(label="增强结果图片", interactive=False)
|
| 81 |
|
| 82 |
+
# 选择图片自动显示原图
|
| 83 |
+
enhance_select.change(fn=show_enhance_input, inputs=enhance_select, outputs=enhance_input_img)
|
| 84 |
+
# 按钮显示增强结果
|
| 85 |
+
enhance_btn.click(fn=enhance_demo, inputs=enhance_select, outputs=enhance_output_img)
|
| 86 |
+
|
| 87 |
+
# 下方:左右两大模块
|
| 88 |
with gr.Row():
|
| 89 |
+
# 左:图像分割
|
| 90 |
with gr.Column():
|
| 91 |
+
gr.Markdown("### 图像分割模块")
|
| 92 |
+
seg_select = gr.Dropdown(choices=SEG_IMG_NAMES, value=SEG_IMG_NAMES[0], label="选择样例图片", filterable=True)
|
| 93 |
+
seg_input_img = gr.Image(label="输入图片", interactive=False)
|
| 94 |
+
seg_btn = gr.Button("执行分割")
|
| 95 |
+
seg_output_img = gr.Image(label="分割结果图片", interactive=False)
|
| 96 |
|
| 97 |
+
seg_select.change(fn=show_seg_input, inputs=seg_select, outputs=seg_input_img)
|
| 98 |
+
seg_btn.click(fn=segment_demo, inputs=seg_select, outputs=seg_output_img)
|
| 99 |
+
|
| 100 |
+
# 右:疾病诊断
|
| 101 |
with gr.Column():
|
| 102 |
+
gr.Markdown("### 疾病诊断模块")
|
| 103 |
+
diag_select = gr.Dropdown(choices=DIAG_IMG_NAMES, value=DIAG_IMG_NAMES[0], label="选择样例图片", filterable=True)
|
| 104 |
+
diag_input_img = gr.Image(label="输入图片", interactive=False)
|
| 105 |
+
diag_btn = gr.Button("开始诊断")
|
| 106 |
+
diag_result = gr.Textbox(label="诊断结果")
|
| 107 |
+
|
| 108 |
+
diag_select.change(fn=show_diag_input, inputs=diag_select, outputs=diag_input_img)
|
| 109 |
+
diag_btn.click(fn=diagnose_demo, inputs=diag_select, outputs=diag_result)
|
| 110 |
|
| 111 |
demo.launch()
|
f1_input/1.png
ADDED
|
Git LFS Details
|
f1_input/10.png
ADDED
|
Git LFS Details
|
f1_input/11.png
ADDED
|
Git LFS Details
|
f1_input/12.png
ADDED
|
Git LFS Details
|
f1_input/13.png
ADDED
|
Git LFS Details
|
f1_input/14.png
ADDED
|
Git LFS Details
|
f1_input/15.png
ADDED
|
Git LFS Details
|
f1_input/16.png
ADDED
|
Git LFS Details
|
f1_input/17.png
ADDED
|
Git LFS Details
|
f1_input/18.png
ADDED
|
Git LFS Details
|
f1_input/19.png
ADDED
|
Git LFS Details
|
f1_input/2.png
ADDED
|
Git LFS Details
|
f1_input/20.png
ADDED
|
Git LFS Details
|
f1_input/21.png
ADDED
|
Git LFS Details
|
f1_input/22.png
ADDED
|
Git LFS Details
|
f1_input/23.png
ADDED
|
Git LFS Details
|
f1_input/24.png
ADDED
|
Git LFS Details
|
f1_input/25.png
ADDED
|
Git LFS Details
|
f1_input/26.png
ADDED
|
Git LFS Details
|
f1_input/27.png
ADDED
|
Git LFS Details
|
f1_input/28.png
ADDED
|
Git LFS Details
|
f1_input/29.png
ADDED
|
Git LFS Details
|
f1_input/3.png
ADDED
|
Git LFS Details
|
f1_input/30.png
ADDED
|
Git LFS Details
|
f1_input/4.png
ADDED
|
Git LFS Details
|
f1_input/5.png
ADDED
|
Git LFS Details
|
f1_input/6.png
ADDED
|
Git LFS Details
|
f1_input/7.png
ADDED
|
Git LFS Details
|
f1_input/8.png
ADDED
|
Git LFS Details
|
f1_input/9.png
ADDED
|
Git LFS Details
|
f1_output/1.png
ADDED
|
Git LFS Details
|
f1_output/10.png
ADDED
|
Git LFS Details
|
f1_output/11.png
ADDED
|
Git LFS Details
|
f1_output/12.png
ADDED
|
Git LFS Details
|
f1_output/13.png
ADDED
|
Git LFS Details
|
f1_output/14.png
ADDED
|
Git LFS Details
|
f1_output/15.png
ADDED
|
Git LFS Details
|
f1_output/16.png
ADDED
|
Git LFS Details
|
f1_output/17.png
ADDED
|
Git LFS Details
|
f1_output/18.png
ADDED
|
Git LFS Details
|
f1_output/19.png
ADDED
|
Git LFS Details
|
f1_output/2.png
ADDED
|
Git LFS Details
|
f1_output/20.png
ADDED
|
Git LFS Details
|
f1_output/21.png
ADDED
|
Git LFS Details
|
f1_output/22.png
ADDED
|
Git LFS Details
|
f1_output/23.png
ADDED
|
Git LFS Details
|
f1_output/24.png
ADDED
|
Git LFS Details
|