prerana-manoj123 commited on
Commit
439b6a5
·
1 Parent(s): 972ddb6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from tensorflow.keras.applications import EfficientNetB0
3
+
4
+ efficient_net = EfficientNetB0(weights='imagenet',include_top=False,input_shape=(150, 150, 3))
5
+
6
+ model = efficient_net.output
7
+ model = tf.keras.layers.GlobalAveragePooling2D()(model)
8
+ model = tf.keras.layers.Dense(64, activation='relu')(model)
9
+ model = tf.keras.layers.Dropout(rate=0.1)(model)
10
+ model = tf.keras.layers.Dense(32, activation='relu')(model)
11
+ model = tf.keras.layers.Dropout(rate=0.1)(model)
12
+ model = tf.keras.layers.Dense(2, activation='sigmoid')(model)
13
+ model = tf.keras.models.Model(inputs=efficient_net.input, outputs=model)
14
+
15
+ model.compile(loss='binary_crossentropy',optimizer = 'Adam', metrics= ['accuracy'])
16
+
17
+ model.load_weights('/kaggle/working')
18
+
19
+ import gradio as gr
20
+
21
+ def cardiomegaly(img):
22
+ img = img.reshape(1, 150, 150, 3)
23
+ prediction = model.predict(img).tolist()[0]
24
+ class_names = ["False", "True"]
25
+ return {class_names[i]: prediction[i] for i in range(2)}
26
+ #set the user uploaded image as the input array
27
+ #match same shape as the input shape in the model
28
+ im = gr.inputs.Image(shape=(150, 150), image_mode='RGB', invert_colors=False, source="upload")
29
+ #setup the interface
30
+ iface = gr.Interface(
31
+ fn = cardiomegaly,
32
+ inputs = im,
33
+ outputs = gr.outputs.Label(),
34
+ )
35
+ iface.launch(share=True)