szili2011 commited on
Commit
b6096d5
1 Parent(s): 0ad0972

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load the trained model (ensure the model file is uploaded)
7
+ model = tf.keras.models.load_model('best_model.h5')
8
+
9
+ # Define the prediction function
10
+ def classify_image(img):
11
+ img = img.resize((150, 150)) # Resize to match model input
12
+ img = np.array(img) / 255.0 # Normalize pixel values
13
+ img = np.expand_dims(img, axis=0) # Add batch dimension
14
+
15
+ # Make prediction
16
+ prediction = model.predict(img)
17
+ class_names = ['Boy', 'Girl'] # Labels for prediction
18
+ predicted_class = class_names[np.argmax(prediction)]
19
+
20
+ return predicted_class
21
+
22
+ # Create Gradio interface
23
+ interface = gr.Interface(
24
+ fn=classify_image,
25
+ inputs=gr.inputs.Image(type="pil"),
26
+ outputs=gr.outputs.Label(),
27
+ title="Boy or Girl Classifier",
28
+ description="Upload an image, and the model will predict whether it's a boy or a girl."
29
+ )
30
+
31
+ # Launch the app
32
+ interface.launch()