File size: 1,284 Bytes
be0b780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20641f0
be0b780
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a2d037
a833c5b
be0b780
 
 
1
2
3
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
32
33
34
35
36
37
38
39
40
from PIL import Image, ImageDraw
from transformers import pipeline
import datasets
import gradio as gr
import os
from datasets import load_dataset

data = load_dataset("Francesco/brain-tumor-m2pbp")
pipe = pipeline("object-detection", model="DunnBC22/yolos-tiny-Brain_Tumor_Detection")

def Processing(Image):
  
  data = pipe(Image)

  for Num_of_Label in range(len(data)) :

    Color_List = ["purple", "yellow", "blue","red"]

    box = data[Num_of_Label]['box']

    xmin, ymin, xmax, ymax = box['xmin'], box['ymin'], box['xmax'], box['ymax']

    draw = ImageDraw.Draw(Image)

    draw.rectangle([xmin, ymin, xmax, ymax], outline= Color_List[Num_of_Label], width=2)

  return Image
def create_brain_tumor_detect() :
  with gr.Blocks() as Brain_Tumor_Detect:
      gr.Markdown("Hãy tải ảnh lên và nhấn **Xử Lý** để khoanh vùng u não.")
      with gr.Row():
         

          inp = gr.Image(label = "Xin Nhập Ảnh Vào", type = 'pil', height=512, width=512,
          value=os.path.join(os.path.dirname(__file__), "../anh/braintt.jpg"),interactive=True)
          out = gr.Image(label = "Kết Quả", type = 'pil', height=512, width=512)
      btn = gr.Button("Xử Lý")
      btn.click(fn=Processing, inputs= inp, outputs=out)
  return Brain_Tumor_Detect