sharren commited on
Commit
b1f560b
β€’
1 Parent(s): 7bc3e0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -41
app.py CHANGED
@@ -2,82 +2,67 @@ import streamlit as st
2
  import pandas as pd
3
  import requests
4
  from dotenv import load_dotenv
 
5
  from transformers import pipeline
6
  from PIL import Image
 
7
  from info import akiec, bcc, bkl, df, mel, nv, vasc, vit_base_patch_16
8
 
9
  load_dotenv()
10
 
11
  URL = 'https://i.stack.imgur.com/gPR77.jpg'
12
 
 
13
  def download_image():
14
  if st.session_state.img_url:
15
- st.session_state['image'] = Image.open(requests.get(st.session_state.img_url, stream=True).raw)
 
16
  else:
17
- st.session_state['image'] = None
 
18
 
19
  def file_upload():
20
  if st.session_state.file_upload:
21
  st.session_state['image'] = Image.open(st.session_state.file_upload)
22
  else:
23
- st.session_state['image'] = None
 
24
 
25
  def cam_upload():
26
  if st.session_state.camera:
27
  st.session_state['image'] = Image.open(st.session_state.camera)
28
  else:
29
- st.session_state['image'] = None
 
30
 
31
- # Initialize session state
32
  if 'image' not in st.session_state:
33
  st.session_state['image'] = Image.open(requests.get(URL, stream=True).raw)
34
 
35
  st.header("Skin Cancer Classifier")
36
 
37
  with st.sidebar:
38
- img_upload_tab, cam_upload_tab, url_upload_tab = st.tabs(['πŸ“‚ Upload', 'πŸ“Έ CAMERA', 'πŸ”— URL'])
 
39
 
40
  with img_upload_tab:
41
- st.file_uploader(label="Upload a Skin Lesion", on_change=file_upload, key='file_upload')
 
 
42
  with cam_upload_tab:
43
- st.camera_input(label='Take a picture of Skin Lesion', on_change=cam_upload, key='camera')
 
 
44
  with url_upload_tab:
45
- st.text_input(label="Enter the Skin Lesion URL", value=URL, on_change=download_image, key="img_url")
 
 
46
 
47
- if st.session_state.image:
48
  st.image(st.session_state['image'])
49
 
50
- st.button(label='Analyze Skin Lesion', type='primary', use_container_width=True, key='analyze_btn')
51
-
52
- # Display initial information from info.py
53
- tab_1, tab_2, tab_3, tab_4, tab_5, tab_6, tab_7 = st.tabs([
54
- 'Actinic Keratoses', 'Basal Cell Carcinoma', 'Benign Keratosis',
55
- 'Dermatofibroma', 'Melanoma', 'Melanocytic Nevi', 'Vascular Lesion'])
56
-
57
- with tab_1:
58
- st.subheader('Actinic Keratoses')
59
- st.markdown(body=akiec)
60
- with tab_2:
61
- st.subheader('Basal Cell Carcinoma')
62
- st.markdown(body=bcc)
63
- with tab_3:
64
- st.subheader('Benign Lesions of the Keratosis Type')
65
- st.markdown(body=bkl)
66
- with tab_4:
67
- st.subheader('Dermatofibroma')
68
- st.markdown(body=df)
69
- with tab_5:
70
- st.subheader('Melanoma')
71
- st.markdown(body=mel)
72
- with tab_6:
73
- st.subheader('Melanocytic Nevi')
74
- st.markdown(body=nv)
75
- with tab_7:
76
- st.subheader('Vascular Lesion')
77
- st.markdown(body=vasc)
78
-
79
- # Analyze the image if the button is pressed
80
- if st.session_state.get('image') is not None and st.session_state.get('analyze_btn'):
81
  with st.spinner("Analyzing..."):
82
  pipe = pipeline("image-classification", model="sharren/vit-beta2-0.99")
83
  response = pipe(st.session_state['image'])
@@ -95,3 +80,30 @@ if st.session_state.get('image') is not None and st.session_state.get('analyze_b
95
 
96
  with st.expander(label="Model Details"):
97
  st.markdown(body=vit_base_patch_16)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import pandas as pd
3
  import requests
4
  from dotenv import load_dotenv
5
+
6
  from transformers import pipeline
7
  from PIL import Image
8
+
9
  from info import akiec, bcc, bkl, df, mel, nv, vasc, vit_base_patch_16
10
 
11
  load_dotenv()
12
 
13
  URL = 'https://i.stack.imgur.com/gPR77.jpg'
14
 
15
+
16
  def download_image():
17
  if st.session_state.img_url:
18
+ st.session_state['image'] = Image.open(
19
+ requests.get(st.session_state.img_url, stream=True).raw)
20
  else:
21
+ del st.session_state['image']
22
+
23
 
24
  def file_upload():
25
  if st.session_state.file_upload:
26
  st.session_state['image'] = Image.open(st.session_state.file_upload)
27
  else:
28
+ del st.session_state['image']
29
+
30
 
31
  def cam_upload():
32
  if st.session_state.camera:
33
  st.session_state['image'] = Image.open(st.session_state.camera)
34
  else:
35
+ del st.session_state['image']
36
+
37
 
 
38
  if 'image' not in st.session_state:
39
  st.session_state['image'] = Image.open(requests.get(URL, stream=True).raw)
40
 
41
  st.header("Skin Cancer Classifier")
42
 
43
  with st.sidebar:
44
+ img_upload_tab, cam_upload_tab, url_upload_tab = st.tabs(
45
+ ['πŸ“‚ Upload', 'πŸ“Έ CAMERA', 'πŸ”— URL'])
46
 
47
  with img_upload_tab:
48
+ uploaded_img = st.file_uploader(
49
+ label="Upload a Skin Lesion", on_change=file_upload, key='file_upload'
50
+ )
51
  with cam_upload_tab:
52
+ camera_img = st.camera_input(
53
+ label='Take a picture of a Skin Lesion', on_change=cam_upload, key='camera'
54
+ )
55
  with url_upload_tab:
56
+ img_url = st.text_input(
57
+ label="Enter the Skin Lesion URL", value=URL, on_change=download_image, key="img_url"
58
+ )
59
 
60
+ if 'image' in st.session_state:
61
  st.image(st.session_state['image'])
62
 
63
+ analyze_btn = st.button(label='Analyze Skin Lesion', type='primary', use_container_width=True, key='analyze_btn')
64
+
65
+ if 'image' in st.session_state and st.session_state['analyze_btn']:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  with st.spinner("Analyzing..."):
67
  pipe = pipeline("image-classification", model="sharren/vit-beta2-0.99")
68
  response = pipe(st.session_state['image'])
 
80
 
81
  with st.expander(label="Model Details"):
82
  st.markdown(body=vit_base_patch_16)
83
+
84
+ else:
85
+ tab_1, tab_2, tab_3, tab_4, tab_5, tab_6, tab_7 = st.tabs([
86
+ 'Actinic Keratoses', 'Basal Cell Carcinoma', 'Benign Keratosis', 'Dermatofibroma',
87
+ 'Melanoma', 'Melanocytic Nevi', 'Vascular Lesion'
88
+ ])
89
+ with tab_1:
90
+ st.subheader('Actinic Keratoses')
91
+ st.markdown(body=akiec)
92
+ with tab_2:
93
+ st.subheader('Basal Cell Carcinoma')
94
+ st.markdown(body=bcc)
95
+ with tab_3:
96
+ st.subheader('Benign Lesions of the Keratosis Type')
97
+ st.markdown(body=bkl)
98
+ with tab_4:
99
+ st.subheader('Dermatofibroma')
100
+ st.markdown(body=df)
101
+ with tab_5:
102
+ st.subheader('Melanoma')
103
+ st.markdown(body=mel)
104
+ with tab_6:
105
+ st.subheader('Melanocytic Nevi')
106
+ st.markdown(body=nv)
107
+ with tab_7:
108
+ st.subheader('Vascular Lesion')
109
+ st.markdown(body=vasc)