Arvndms commited on
Commit
7e1d4ae
1 Parent(s): a3bbace

Upload 14 files

Browse files
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ HF_HOME='./huggingface_folder'
2
+ HF_HUB_CACHE='./huggingface_folder/hub'
.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
+ huggingface_folder/hub/models--Ajay-user--vit-base-patch16-224-finetuned-pneumonia-detection/blobs/cf194b576e2d571995cc9c1cbe99a5ba9e80e0023d2a22e43f8abf035560b002 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import requests
5
+ from dotenv import load_dotenv
6
+
7
+ from transformers import pipeline
8
+ from PIL import Image
9
+
10
+ from info import pneumonia, covid19, vit_base_patch_16
11
+
12
+ load_dotenv()
13
+
14
+ URL = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTcY7VeTAy72aEPJbHmABvnGzW5gzrvSKRzOg&usqp=CAU'
15
+
16
+
17
+ def download_image():
18
+ if st.session_state.img_url:
19
+ st.session_state['image'] = Image.open(
20
+ requests.get(st.session_state.img_url, stream=True).raw)
21
+ else:
22
+ del st.session_state['image']
23
+
24
+
25
+ def file_upload():
26
+ if st.session_state.file_upload:
27
+ st.session_state['image'] = Image.open(st.session_state.file_upload)
28
+ else:
29
+ del st.session_state['image']
30
+
31
+
32
+ def cam_upload():
33
+ if st.session_state.camera:
34
+ st.session_state['image'] = st.session_state.camera
35
+ else:
36
+ del st.session_state['image']
37
+
38
+
39
+ if 'image' not in st.session_state:
40
+ st.session_state['image'] = Image.open(requests.get(URL, stream=True).raw)
41
+
42
+ st.header("Pneumonia and Covid19 Detector")
43
+
44
+ with st.sidebar:
45
+ img_upload, cam_upload, url_upload = st.tabs(
46
+ ['📂 Upload', '📸 CAMERA', '🔗 URL'])
47
+
48
+ with img_upload:
49
+ uploaded_img = st.file_uploader(
50
+ label="Upload an X-ray image", on_change=file_upload, key='file_upload'
51
+ )
52
+ with cam_upload:
53
+ camera_img = st.camera_input(
54
+ label='Take a picture of X-ray', on_change=cam_upload, key='camera'
55
+ )
56
+ with url_upload:
57
+ img_url = st.text_input(
58
+ label="Enter the X-ray URL", value=URL, on_change=download_image, key="img_url"
59
+ )
60
+
61
+ st.image(st.session_state.image)
62
+
63
+ analyze_btn = st.button(label='Analyze X-ray', type='primary',
64
+ use_container_width=True, key='analyze_btn')
65
+
66
+ if st.session_state.image and st.session_state.analyze_btn:
67
+ with st.spinner():
68
+ pipe = pipeline("image-classification",
69
+ model="Ajay-user/vit-base-patch16-224-finetuned-pneumonia-detection")
70
+ response = pipe(st.session_state.image)
71
+
72
+ df = pd.DataFrame(response)
73
+ result = df.nlargest(n=1, columns='score')
74
+ result_body = f'Model predicts : {result["label"].item()} with {result["score"].item()*100 :0.2f}% confidence'
75
+
76
+ with st.expander(label=result_body, expanded=True):
77
+ st.subheader(body=f':red[{result["label"].item()}] Detected')
78
+ st.bar_chart(data=df, x='label', y='score')
79
+
80
+ with st.expander(label="X-ray image analyzed"):
81
+ st.image(st.session_state.image)
82
+
83
+ with st.expander(label="Model Details"):
84
+ st.markdown(body=vit_base_patch_16)
85
+
86
+ else:
87
+ tab_1, tab_2 = st.tabs(['Pneumonia', 'Coronavirus'])
88
+ with tab_1:
89
+ st.subheader('Pneumonia')
90
+ st.markdown(body=pneumonia)
91
+ with tab_2:
92
+ st.subheader('Coronavirus')
93
+ st.markdown(body=covid19)
huggingface_folder/hub/.locks/models--Ajay-user--vit-base-patch16-224-finetuned-pneumonia-detection/273d24924a8bd10227b532d603484f165dcb0b5d.lock ADDED
File without changes
huggingface_folder/hub/.locks/models--Ajay-user--vit-base-patch16-224-finetuned-pneumonia-detection/cf194b576e2d571995cc9c1cbe99a5ba9e80e0023d2a22e43f8abf035560b002.lock ADDED
File without changes
huggingface_folder/hub/.locks/models--Ajay-user--vit-base-patch16-224-finetuned-pneumonia-detection/f01e5e4a53624256f48d3bc82b547e67ee5dda49.lock ADDED
File without changes
huggingface_folder/hub/models--Ajay-user--vit-base-patch16-224-finetuned-pneumonia-detection/blobs/273d24924a8bd10227b532d603484f165dcb0b5d ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "do_rescale": true,
4
+ "do_resize": true,
5
+ "image_mean": [
6
+ 0.5,
7
+ 0.5,
8
+ 0.5
9
+ ],
10
+ "image_processor_type": "ViTImageProcessor",
11
+ "image_std": [
12
+ 0.5,
13
+ 0.5,
14
+ 0.5
15
+ ],
16
+ "resample": 2,
17
+ "rescale_factor": 0.00392156862745098,
18
+ "size": {
19
+ "height": 224,
20
+ "width": 224
21
+ }
22
+ }
huggingface_folder/hub/models--Ajay-user--vit-base-patch16-224-finetuned-pneumonia-detection/blobs/cf194b576e2d571995cc9c1cbe99a5ba9e80e0023d2a22e43f8abf035560b002 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf194b576e2d571995cc9c1cbe99a5ba9e80e0023d2a22e43f8abf035560b002
3
+ size 343227052
huggingface_folder/hub/models--Ajay-user--vit-base-patch16-224-finetuned-pneumonia-detection/blobs/f01e5e4a53624256f48d3bc82b547e67ee5dda49 ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "google/vit-base-patch16-224",
3
+ "architectures": [
4
+ "ViTForImageClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.0,
7
+ "encoder_stride": 16,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.0,
10
+ "hidden_size": 768,
11
+ "id2label": {
12
+ "0": "COVID19",
13
+ "1": "NORMAL",
14
+ "2": "PNEUMONIA"
15
+ },
16
+ "image_size": 224,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "label2id": {
20
+ "COVID19": 0,
21
+ "NORMAL": 1,
22
+ "PNEUMONIA": 2
23
+ },
24
+ "layer_norm_eps": 1e-12,
25
+ "model_type": "vit",
26
+ "num_attention_heads": 12,
27
+ "num_channels": 3,
28
+ "num_hidden_layers": 12,
29
+ "patch_size": 16,
30
+ "problem_type": "single_label_classification",
31
+ "qkv_bias": true,
32
+ "torch_dtype": "float32",
33
+ "transformers_version": "4.38.2"
34
+ }
huggingface_folder/hub/models--Ajay-user--vit-base-patch16-224-finetuned-pneumonia-detection/refs/main ADDED
@@ -0,0 +1 @@
 
 
1
+ d301c243e1d96c5531bc56dd8c49f4aeb1cdc0d6
huggingface_folder/hub/version.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ 1
info.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pneumonia = '''
2
+ Pneumonia is an infection that inflames the air sacs in one or both lungs.
3
+ The air sacs may fill with fluid or pus (purulent material),
4
+ causing cough with phlegm or pus, fever, chills, and difficulty breathing.
5
+ A variety of organisms, including bacteria, viruses and fungi, can cause pneumonia.
6
+
7
+ Pneumonia can range in seriousness from mild to life-threatening.
8
+ It is most serious for infants and young children, people older than age 65,
9
+ and people with health problems or weakened immune systems.
10
+
11
+ #### Symptoms
12
+ The signs and symptoms of pneumonia vary from mild to severe,
13
+ depending on factors such as the type of germ causing the infection,
14
+ and your age and overall health.
15
+ Mild signs and symptoms often are similar to those of a cold or flu, but they last longer.
16
+
17
+ #### Signs and symptoms of pneumonia may include:
18
+
19
+ * Chest pain when you breathe or cough
20
+ * Confusion or changes in mental awareness (in adults age 65 and older)
21
+ * Cough, which may produce phlegm
22
+ * Fatigue
23
+ * Fever, sweating and shaking chills
24
+ * Lower than normal body temperature (in adults older than age 65 and people with weak immune systems)
25
+ * Nausea, vomiting or diarrhea
26
+ * Shortness of breath
27
+
28
+ Newborns and infants may not show any sign of the infection.
29
+ Or they may vomit, have a fever and cough,
30
+ appear restless or tired and without energy, or have difficulty breathing and eating.
31
+
32
+ #### When to see a doctor
33
+ See your doctor if you have difficulty breathing,
34
+ chest pain, persistent fever of 102 F (39 C) or higher, or persistent cough,
35
+ especially if you're coughing up pus.
36
+
37
+ #### It's especially important that people in these high-risk groups see a doctor:
38
+
39
+ * Adults older than age 65
40
+ * Children younger than age 2 with signs and symptoms
41
+ * People with an underlying health condition or weakened immune system
42
+ * People receiving chemotherapy or taking medication that suppresses the immune system
43
+
44
+ For some older adults and people with heart failure or chronic lung problems, pneumonia can quickly become a life-threatening condition.
45
+ '''
46
+
47
+
48
+ covid19 = '''
49
+
50
+ Coronavirus disease (COVID-19) is an infectious disease caused by the SARS-CoV-2 virus.
51
+
52
+ Most people infected with the virus will experience mild to moderate respiratory illness and recover without requiring special treatment. However, some will become seriously ill and require medical attention. Older people and those with underlying medical conditions like cardiovascular disease, diabetes, chronic respiratory disease, or cancer are more likely to develop serious illness. Anyone can get sick with COVID-19 and become seriously ill or die at any age.
53
+
54
+ The best way to prevent and slow down transmission is to be well informed about the disease and how the virus spreads. Protect yourself and others from infection by staying at least 1 metre apart from others, wearing a properly fitted mask, and washing your hands or using an alcohol-based rub frequently. Get vaccinated when it’s your turn and follow local guidance.
55
+
56
+ The virus can spread from an infected person’s mouth or nose in small liquid particles when they cough, sneeze, speak, sing or breathe. These particles range from larger respiratory droplets to smaller aerosols. It is important to practice respiratory etiquette, for example by coughing into a flexed elbow, and to stay home and self-isolate until you recover if you feel unwell.
57
+
58
+ #### Symptoms of COVID-19
59
+ * Fever or chills
60
+ * Cough
61
+ * Shortness of breath or difficulty breathing
62
+ * Fatigue
63
+ * Muscle or body aches
64
+ * Headache
65
+ * New loss of taste or smell
66
+ * Sore throat
67
+ * Congestion or runny nose
68
+ * Nausea or vomiting
69
+ * Diarrhea
70
+
71
+
72
+ #### When to Seek Emergency Medical Attention
73
+ **Look for emergency warning signs* for COVID 19:**
74
+
75
+ * Trouble breathing
76
+ * Persistent pain or pressure in the chest
77
+ * New confusion
78
+ * Inability to wake or stay awake
79
+ * Pale, gray, or blue-colored skin, lips, or nail beds, depending on skin tone
80
+
81
+ '''
82
+
83
+ vit_base_patch_16 = '''
84
+
85
+ # vit-base-patch16-224-finetuned-pneumonia-detection
86
+
87
+ This model is a fine-tuned version of [google/vit-base-patch16-224](https://huggingface.co/google/vit-base-patch16-224) on the imagefolder dataset.
88
+ It achieves the following results on the evaluation set:
89
+ - Loss: 0.0938
90
+ - Accuracy: 0.9728
91
+
92
+
93
+ ### Training hyperparameters
94
+
95
+ The following hyperparameters were used during training:
96
+ - learning_rate: 5e-05
97
+ - train_batch_size: 64
98
+ - eval_batch_size: 64
99
+ - seed: 42
100
+ - gradient_accumulation_steps: 4
101
+ - total_train_batch_size: 256
102
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
103
+ - lr_scheduler_type: linear
104
+ - lr_scheduler_warmup_ratio: 0.1
105
+ - num_epochs: 3
106
+
107
+ ### Training results
108
+
109
+ | Training Loss | Epoch | Step | Validation Loss | Accuracy |
110
+ |:-------------:|:-----:|:----:|:---------------:|:--------:|
111
+ | 0.2082 | 0.99 | 20 | 0.1462 | 0.9402 |
112
+ | 0.0832 | 1.98 | 40 | 0.0998 | 0.9658 |
113
+ | 0.0517 | 2.96 | 60 | 0.0938 | 0.9728 |
114
+
115
+
116
+ ### Framework versions
117
+
118
+ - Transformers 4.38.2
119
+ - Pytorch 2.1.2
120
+ - Datasets 2.18.0
121
+ - Tokenizers 0.15.2
122
+ '''
requirements.txt ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.2.0
2
+ attrs==23.2.0
3
+ blinker==1.7.0
4
+ cachetools==5.3.3
5
+ certifi==2024.2.2
6
+ charset-normalizer==3.3.2
7
+ click==8.1.7
8
+ filelock==3.13.1
9
+ fsspec==2024.2.0
10
+ gitdb==4.0.11
11
+ GitPython==3.1.42
12
+ huggingface-hub==0.21.4
13
+ idna==3.6
14
+ importlib_metadata==7.0.2
15
+ Jinja2==3.1.3
16
+ jsonschema==4.21.1
17
+ jsonschema-specifications==2023.12.1
18
+ markdown-it-py==3.0.0
19
+ MarkupSafe==2.1.5
20
+ mdurl==0.1.2
21
+ mpmath==1.3.0
22
+ networkx==3.2.1
23
+ numpy==1.26.4
24
+ nvidia-cublas-cu12==12.1.3.1
25
+ nvidia-cuda-cupti-cu12==12.1.105
26
+ nvidia-cuda-nvrtc-cu12==12.1.105
27
+ nvidia-cuda-runtime-cu12==12.1.105
28
+ nvidia-cudnn-cu12==8.9.2.26
29
+ nvidia-cufft-cu12==11.0.2.54
30
+ nvidia-curand-cu12==10.3.2.106
31
+ nvidia-cusolver-cu12==11.4.5.107
32
+ nvidia-cusparse-cu12==12.1.0.106
33
+ nvidia-nccl-cu12==2.19.3
34
+ nvidia-nvjitlink-cu12==12.4.99
35
+ nvidia-nvtx-cu12==12.1.105
36
+ packaging==23.2
37
+ pandas==2.2.1
38
+ pillow==10.2.0
39
+ protobuf==4.25.3
40
+ pyarrow==15.0.0
41
+ pydeck==0.8.1b0
42
+ Pygments==2.17.2
43
+ python-dateutil==2.9.0.post0
44
+ python-dotenv==1.0.1
45
+ pytz==2024.1
46
+ PyYAML==6.0.1
47
+ referencing==0.33.0
48
+ regex==2023.12.25
49
+ requests==2.31.0
50
+ rich==13.7.1
51
+ rpds-py==0.18.0
52
+ safetensors==0.4.2
53
+ six==1.16.0
54
+ smmap==5.0.1
55
+ streamlit==1.31.1
56
+ sympy==1.12
57
+ tenacity==8.2.3
58
+ tokenizers==0.15.2
59
+ toml==0.10.2
60
+ toolz==0.12.1
61
+ torch==2.2.1
62
+ tornado==6.4
63
+ tqdm==4.66.2
64
+ transformers==4.38.2
65
+ triton==2.2.0
66
+ typing_extensions==4.10.0
67
+ tzdata==2024.1
68
+ tzlocal==5.2
69
+ urllib3==2.2.1
70
+ validators==0.22.0
71
+ watchdog==4.0.0
72
+ zipp==3.17.0