Zeeshan01 commited on
Commit
5bede1f
·
1 Parent(s): cf3bd8f

Upload folder using huggingface_hub

Browse files
Files changed (7) hide show
  1. README.md +1 -7
  2. __pycache__/app.cpython-310.pyc +0 -0
  3. app.py +60 -0
  4. c1.png +0 -0
  5. c2.jpeg +0 -0
  6. model/covid.h5 +3 -0
  7. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
  title: Covid
3
- emoji: 👁
4
- colorFrom: green
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 3.35.2
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Covid
3
+ app_file: app.py
 
 
4
  sdk: gradio
5
  sdk_version: 3.35.2
 
 
6
  ---
 
 
__pycache__/app.cpython-310.pyc ADDED
Binary file (1.16 kB). View file
 
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+
7
+
8
+
9
+
10
+
11
+ # Initial parameters for pretrained model
12
+ IMG_SIZE = 300
13
+
14
+ labelCOVID = {
15
+ 'COVID-19': 0,
16
+ 'Normal': 1,
17
+ 'Viral Pneumonia': 2,
18
+ 'Lung_Opacity': 3
19
+ }
20
+ # Load the model from the H5 file
21
+ model = tf.keras.models.load_model('model/covid.h5')
22
+
23
+ # Define the prediction function
24
+ def predict(img):
25
+ img_height = 150
26
+ img_width = 150
27
+
28
+ # Convert the NumPy array to a PIL Image object
29
+ pil_img = Image.fromarray(img)
30
+
31
+ # Resize the image using the PIL Image object
32
+ pil_img = pil_img.resize((img_height, img_width))
33
+
34
+ # Convert the PIL Image object to a NumPy array
35
+ x = tf.keras.preprocessing.image.img_to_array(pil_img)
36
+
37
+ x = x.reshape(1, img_height, img_width, 3)
38
+ np.set_printoptions(formatter={'float': '{: 0.3f}'.format})
39
+
40
+
41
+ predi = model.predict(x)
42
+ accuracy_of_class = '{:.1f}'.format(predi[0][np.argmax(predi)] * 100) + "%"
43
+ classes = list(labelCOVID.keys())[np.argmax(predi)]
44
+ context = {
45
+ 'predictedLabel': classes,
46
+ # 'y_class': y_class,
47
+ # 'z_class': z_class,
48
+ 'accuracy_of_class': accuracy_of_class
49
+ }
50
+
51
+
52
+
53
+ return context
54
+
55
+
56
+
57
+ demo = gr.Interface(fn=predict, inputs="image", outputs="text" , examples=[["c1.png"],["c2.jpeg"]],)
58
+
59
+ demo.launch()
60
+
c1.png ADDED
c2.jpeg ADDED
model/covid.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92dcd072a68adfc0c00fd167d74ba64e0a188539546df0c9101459c011492463
3
+ size 202133552
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow
2
+ numpy
3
+ pillow