Nina-HK commited on
Commit
2c6e3b0
1 Parent(s): 632f959
Files changed (1) hide show
  1. app.py +26 -31
app.py CHANGED
@@ -36,43 +36,38 @@ labels_cnn = {0: 'healthy', 1: 'patient'}
36
  labels_efficientnet = {0: 'healthy', 1: 'patient'}
37
 
38
  def classify_cnn(inp):
39
- img = np.array(inp)
40
- img = img.reshape((1, 224, 224, 3))
41
- img = densenet.preprocess_input(img)
42
- prediction = model_cnn.predict(img)
43
  confidence = float(prediction[0])
44
  return {labels_cnn[prediction.argmax()]: confidence}
45
 
46
  def classify_efficientnet(inp):
47
- img = np.array(inp)
48
- img = img.reshape((1, 224, 224, 3))
49
- img = efficientnet.preprocess_input(img)
50
- prediction = model_efficientnet.predict(img)
51
  confidence = float(prediction[0])
52
  return {labels_efficientnet[prediction.argmax()]: confidence}
 
 
 
 
 
 
 
 
53
 
54
- cnn_interface = gr.Interface(fn=classify_cnn,
55
- inputs=gr.inputs.Image(shape=(224, 224)),
56
- outputs=gr.outputs.Label(num_top_classes=2),
57
- title="CNN Binary Image Classification",
58
- description="Classify an image as healthy or patient using a CNN model.",
59
- examples=[['300104.png']]
60
- )
61
 
62
- efficientnet_interface = gr.Interface(fn=classify_efficientnet,
63
- inputs=gr.inputs.Image(shape=(224, 224)),
64
- outputs=gr.outputs.Label(num_top_classes=2),
65
- title="EfficientNet Binary Image Classification",
66
- description="Classify an image as healthy or patient using an EfficientNet model.",
67
- examples=[['300104.png']]
68
- )
69
- # create a combined interface with tabs for each binary classification model
70
- demo = gr.Interface([cnn_interface, efficientnet_interface],
71
- "tab",
72
- title="Binary Image Classification",
73
- description="Classify an image as healthy or patient using different binary classification models."
74
- )
75
-
76
- demo.launch()
77
-
78
 
 
 
36
  labels_efficientnet = {0: 'healthy', 1: 'patient'}
37
 
38
  def classify_cnn(inp):
39
+ inp = inp.reshape((-1, 224, 224, 3))
40
+ inp = tf.keras.applications.densenet.preprocess_input(inp)
41
+ prediction = model_cnn.predict(inp)
 
42
  confidence = float(prediction[0])
43
  return {labels_cnn[prediction.argmax()]: confidence}
44
 
45
  def classify_efficientnet(inp):
46
+ inp = inp.reshape((-1, 224, 224, 3))
47
+ inp = tf.keras.applications.densenet.preprocess_input(inp)
48
+ prediction = model_efficientnet.predict(inp)
 
49
  confidence = float(prediction[0])
50
  return {labels_efficientnet[prediction.argmax()]: confidence}
51
+
52
+ # Create the Gradio interfaces for each binary classification model
53
+ cnn_binary_interface = gr.Interface(fn=classify_cnn,
54
+ inputs=gr.inputs.Image(shape=(224, 224)),
55
+ outputs=gr.outputs.Label(num_top_classes=2),
56
+ title="CNN Binary Image Classification",
57
+ description="Classify an image as healthy or patient using a CNN model.",
58
+ examples=[['300104.png']])
59
 
60
+ efficientnet_binary_interface = gr.Interface(fn=classify_efficientnet,
61
+ inputs=gr.inputs.Image(shape=(224, 224)),
62
+ outputs=gr.outputs.Label(num_top_classes=2),
63
+ title="EfficientNet Binary Image Classification",
64
+ description="Classify an image as healthy or patient using an EfficientNet model.",
65
+ examples=[['300104.png']])
 
66
 
67
+ # Create the Gradio demo that allows the user to choose between the two binary classification models
68
+ binary_demo = gr.Interface([cnn_binary_interface, efficientnet_binary_interface],
69
+ "tabs",
70
+ title="Binary Image Classification",
71
+ description="Classify an image as healthy or patient using one of two binary classification models.")
 
 
 
 
 
 
 
 
 
 
 
72
 
73
+ binary_demo.launch()