Spaces:
Running
Running
sandrocalzada
commited on
Commit
•
d1ffd11
1
Parent(s):
990fb44
Upload 3 files
Browse files- app.py +29 -0
- packages.txt +0 -0
- requeriments.txt +3 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import tensorflow as tf
|
4 |
+
import cv2
|
5 |
+
|
6 |
+
# Load your trained model
|
7 |
+
model = tf.keras.models.load_model('path_to_your_model.h5')
|
8 |
+
|
9 |
+
def predict_gender(image):
|
10 |
+
# Convert image to format expected by your model & preprocess
|
11 |
+
img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
|
12 |
+
img = cv2.resize(img, (224, 224)) # Example size
|
13 |
+
img = img / 255.0 # Normalizing
|
14 |
+
img = np.expand_dims(img, axis=0)
|
15 |
+
|
16 |
+
prediction = model.predict(img)
|
17 |
+
|
18 |
+
# Assuming binary classification with a single output neuron
|
19 |
+
return "Male" if prediction[0] < 0.5 else "Female"
|
20 |
+
|
21 |
+
# Define Gradio interface
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=predict_gender,
|
24 |
+
inputs=gr.inputs.Image(type="webcam", label="Capture an Image from Webcam"),
|
25 |
+
outputs=gr.outputs.Label(),
|
26 |
+
live=True
|
27 |
+
)
|
28 |
+
|
29 |
+
iface.launch()
|
packages.txt
ADDED
File without changes
|
requeriments.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
opencv-python
|
3 |
+
tensorflow
|