Nina-HK commited on
Commit
bcaa4d3
1 Parent(s): b3bd50f

two_interface

Browse files
Files changed (1) hide show
  1. app.py +33 -54
app.py CHANGED
@@ -33,58 +33,37 @@ from transformers import pipeline
33
  #labels = ['Healthy', 'Patient']
34
  #labels = {0: 'healthy', 1: 'patient'}
35
 
36
-
37
- # load the binary classification model
38
- model_binary = tf.keras.models.load_model("densenet")
39
-
40
- # load the multi-label classification model
41
- model_multi = tf.keras.models.load_model("densenet")
42
-
43
- # define the labels for the binary classification model
44
- labels_binary = {0: 'healthy', 1: 'patient'}
45
-
46
- # define the labels for the multi-label classification model
47
- labels_multi = {0: 'healthy', 1: 'mild', 2: 'moderate'}
48
-
49
-
50
- # define the function for the binary classification model
51
- def classify_binary(inp):
52
- inp = inp.reshape((-1, 224, 224, 3))
53
- inp = tf.keras.applications.densenet.preprocess_input(inp)
54
- prediction = model_binary.predict(inp)
55
- confidence = float(prediction[0])
56
- label = labels_binary[int(np.round(confidence))]
57
- return {label: confidence}
58
-
59
-
60
- # define the function for the multi-label classification model
61
- def classify_multi(inp):
62
- inp = inp.reshape((-1, 224, 224, 3))
63
- inp = tf.keras.applications.densenet.preprocess_input(inp)
64
- prediction = model_multi.predict(inp)
65
- confidences = {labels_multi[i]: float(prediction[0][i]) for i in range(3)}
66
- return confidences
67
-
68
-
69
- # create the Gradio interface for the binary classification model
70
- binary_interface = gr.Interface(fn=classify_binary,
71
- inputs=gr.inputs.Image(shape=(224, 224)),
72
- outputs=gr.outputs.Label(num_top_classes=2),
73
- title="Binary Image Classification",
74
- description="Classify an image as healthy or patient.",
75
- examples=[['300104.png']]
76
- )
77
-
78
- # create the Gradio interface for the multi-label classification model
79
- multi_interface = gr.Interface(fn=classify_multi,
80
- inputs=gr.inputs.Image(shape=(224, 224)),
81
- outputs=gr.outputs.Label(num_top_classes=3),
82
- title="Multi-class Image Classification",
83
- description="Classify an image as healthy, mild or moderate.",
84
- examples=[['300104.png']]
85
- )
86
-
87
- # create the Gradio app with both interfaces
88
- app = gr.Interface([binary_interface, multi_interface], title="Image Classification App")
89
- app.launch()
90
 
 
33
  #labels = ['Healthy', 'Patient']
34
  #labels = {0: 'healthy', 1: 'patient'}
35
 
36
+ # Load the model
37
+ model = tf.keras.models.load_model("densenet")
38
+
39
+ # Define the labels
40
+ labels = {0: 'healthy', 1: 'patient'}
41
+
42
+ def classify_image(inp):
43
+ inp = inp.reshape((-1, 224, 224, 3))
44
+ inp = tf.keras.applications.densenet.preprocess_input(inp)
45
+ prediction = model.predict(inp)
46
+ confidences = {labels[i]: float(prediction[0][i]) for i in range(2)}
47
+ return confidences
48
+
49
+ # Create the binary interface
50
+ binary_interface = gr.Interface(fn=classify_image,
51
+ inputs=gr.Image(shape=(224, 224)),
52
+ outputs=gr.Label(num_top_classes=2),
53
+ title="Binary Image Classification",
54
+ description="Classify an image as healthy or patient.",
55
+ examples=[['300104.png']]
56
+ )
57
+
58
+ # Create the multi-class interface
59
+ multi_interface = gr.Interface(fn=classify_image,
60
+ inputs=gr.Image(shape=(224, 224)),
61
+ outputs=gr.Label(num_top_classes=3),
62
+ title="Multi-class Image Classification",
63
+ description="Classify an image as healthy, mild or moderate.",
64
+ examples=[['300104.png']]
65
+ )
66
+
67
+ # Launch the app
68
+ gr.Interface([binary_interface, multi_interface], "grid", title="My Image Classification App").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69