fifadotjs commited on
Commit
6da84b2
·
1 Parent(s): 9d75497

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -14
app.py CHANGED
@@ -1,20 +1,15 @@
1
  import streamlit as st
2
  import matplotlib.pyplot as plt
3
- import torchvision
4
- from torchvision.transforms import ToTensor
5
- from transformers import ViTModel
6
- from transformers.modeling_outputs import SequenceClassifierOutput
7
  import torch.nn as nn
8
- import torch.nn.functional as F
9
- from transformers import ViTFeatureExtractor
10
  import torch
11
- import torch.utils.data as data
12
- from torch.autograd import Variable
13
  import numpy as np
14
  import os
15
- import torch.optim as optim
16
  from torchvision.transforms import transforms
17
- from torch.utils.data import DataLoader
18
  from vit_pytorch import ViT
19
  from PIL import Image
20
 
@@ -24,6 +19,7 @@ import math
24
  from functools import partial
25
  import torch
26
  import torch.nn as nn
 
27
  from PIL import Image
28
  from torchvision import transforms
29
  import matplotlib.pyplot as plt
@@ -410,6 +406,7 @@ from functools import partial
410
  import torch
411
  import torch.nn as nn
412
 
 
413
  import io
414
  from PIL import Image
415
  from torchvision import transforms
@@ -594,6 +591,10 @@ except:
594
  st.sidebar.write(factor_reduce)
595
 
596
  return realtime_update,box_color,aspect_ratio,factor_reduce
 
 
 
 
597
  st.title('ระบบวินิฉัยโรคมะเร็งหู')
598
  st.info('กรุณาถ่ายภาพหูอย่างชัดเจนและควรใช้กล้องคุณภาพสูง เพื่อประสิทธิภาพที่ดีที่สุด', icon="ℹ️")
599
  img_path = st.camera_input(label="From camera",label_visibility="hidden")
@@ -636,6 +637,7 @@ except:
636
  _ = cropped_img.thumbnail((224,224))
637
  st.image(cropped_img)
638
 
 
639
  if img_path or img_upload is not None:
640
  image_path = (cropped_img)
641
  result = st.button("วินิฉัย",type="primary",use_container_width=True)
@@ -659,11 +661,23 @@ except:
659
  img = Image.open(path)
660
  predicted, threshold = Classification(path)
661
  print(4*form_score)
662
- newthreshold = float(threshold.replace("%","")) - (4*form_score)
663
- if predicted != 'Not_EarCancer' and newthreshold > 50:
664
- st.markdown(f'<h1 style="color:red;">ชนิดโรค: {predicted} , มั่นใจ: {newthreshold}%</h1>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
665
  else:
666
- st.markdown(f'<h1 style="color:green;">หูปกติ ไม่เป็นโรค , มั่นใจ: {newthreshold}%</h1>', unsafe_allow_html=True)
667
  img_size = tuple(np.array(img.size[::-1]) // int(factor_reduce))
668
  model = VitGenerator(name_model, patch_size,device, evaluate=True, random=False, verbose=True)
669
  visualize_predict(model, img, img_size, patch_size, device)
 
1
  import streamlit as st
2
  import matplotlib.pyplot as plt
3
+
 
 
 
4
  import torch.nn as nn
5
+
 
6
  import torch
7
+
 
8
  import numpy as np
9
  import os
10
+
11
  from torchvision.transforms import transforms
12
+
13
  from vit_pytorch import ViT
14
  from PIL import Image
15
 
 
19
  from functools import partial
20
  import torch
21
  import torch.nn as nn
22
+
23
  from PIL import Image
24
  from torchvision import transforms
25
  import matplotlib.pyplot as plt
 
406
  import torch
407
  import torch.nn as nn
408
 
409
+
410
  import io
411
  from PIL import Image
412
  from torchvision import transforms
 
591
  st.sidebar.write(factor_reduce)
592
 
593
  return realtime_update,box_color,aspect_ratio,factor_reduce
594
+
595
+
596
+
597
+
598
  st.title('ระบบวินิฉัยโรคมะเร็งหู')
599
  st.info('กรุณาถ่ายภาพหูอย่างชัดเจนและควรใช้กล้องคุณภาพสูง เพื่อประสิทธิภาพที่ดีที่สุด', icon="ℹ️")
600
  img_path = st.camera_input(label="From camera",label_visibility="hidden")
 
637
  _ = cropped_img.thumbnail((224,224))
638
  st.image(cropped_img)
639
 
640
+
641
  if img_path or img_upload is not None:
642
  image_path = (cropped_img)
643
  result = st.button("วินิฉัย",type="primary",use_container_width=True)
 
661
  img = Image.open(path)
662
  predicted, threshold = Classification(path)
663
  print(4*form_score)
664
+ if predicted != 'Not_EarCancer':
665
+ newthreshold = float(threshold.replace("%","")) - (4*form_score)
666
+ else:
667
+ newthreshold = float(threshold.replace("%",""))
668
+ if predicted != 'Not_EarCancer':
669
+ if newthreshold > 50:
670
+ if newthreshold >70:
671
+ st.markdown(f'<h1 style="color:red;">ชนิดโรค: {predicted} , มั่นใจ: {newthreshold}%</h1>', unsafe_allow_html=True)
672
+ st.markdown(f'<h1 style="color:red;">🚨 คุณมีความเสี่ยงเป็น{predicted}สูง โปรดปรึกษาแพทย์!</h1>', unsafe_allow_html=True)
673
+ if newthreshold <70:
674
+ st.markdown(f'<h1 style="color:orange;">ชนิดโรค: {predicted} , มั่นใจ: {newthreshold}%</h1>', unsafe_allow_html=True)
675
+ st.markdown(f'<h1 style="color:orange;">🟡 คุณมีโอกาศเป็น{predicted} โปรดเฝ้าระวัง</h1>', unsafe_allow_html=True)
676
+ else:
677
+ st.markdown(f'<h1 style="color:green;">ชนิดโรค: {predicted} , มั่นใจ: {newthreshold}%</h1>', unsafe_allow_html=True)
678
+ st.markdown(f'<h1 style="color:green;">✅ คุณมีโอกาศเป็น{predicted}ต่ำ</h1>', unsafe_allow_html=True)
679
  else:
680
+ st.markdown(f'<h1 style="color:green;">ชนิดโรค: {predicted} , มั่นใจ: {newthreshold}%</h1>', unsafe_allow_html=True)
681
  img_size = tuple(np.array(img.size[::-1]) // int(factor_reduce))
682
  model = VitGenerator(name_model, patch_size,device, evaluate=True, random=False, verbose=True)
683
  visualize_predict(model, img, img_size, patch_size, device)