vargar commited on
Commit
e4a6f06
·
verified ·
1 Parent(s): 54ab631

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import numpy as np
3
+ import gradio as gr
4
+
5
+ # Load the model
6
+ model = tf.keras.models.load_model("vgg19_binary_nonbinary.h5")
7
+
8
+ # Define the preprocessing function
9
+ def preprocess_image(image):
10
+ image = image.resize((224, 224)) # Resize to match model input size
11
+ image = np.array(image) / 255.0 # Normalize pixel values
12
+ image = np.expand_dims(image, axis=0) # Add batch dimension
13
+ return image
14
+
15
+ # Define the prediction function
16
+ def classify_image(image):
17
+ processed_image = preprocess_image(image)
18
+ predictions = model.predict(processed_image)
19
+ class_names = ["binary", "non-binary"]
20
+ confidence = {class_names[i]: float(predictions[0][i]) for i in range(2)}
21
+ return confidence
22
+
23
+ # Create a Gradio interface
24
+ interface = gr.Interface(
25
+ fn=classify_image,
26
+ inputs=gr.Image(type="pil"), # Input is an image
27
+ outputs=gr.Label(num_top_classes=2), # Output is a label with confidence scores
28
+ title="Binary vs Non-Binary Image Classification",
29
+ description="Upload an image to classify it as 'binary' or 'non-binary'.",
30
+ )
31
+
32
+ # Launch the app
33
+ interface.launch()