Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,10 @@ import numpy as np
|
|
8 |
model = load_model('race_prediction_model.h5')
|
9 |
|
10 |
# Define the categories based on your model's output
|
11 |
-
categories = [
|
|
|
|
|
|
|
12 |
|
13 |
# Define the function to classify images
|
14 |
def classify_image(img):
|
@@ -18,7 +21,6 @@ def classify_image(img):
|
|
18 |
img_array /= 255.0
|
19 |
|
20 |
predictions = model.predict(img_array)
|
21 |
-
predicted_class = categories[np.argmax(predictions)]
|
22 |
return {category: float(pred) for category, pred in zip(categories, predictions[0])}
|
23 |
|
24 |
# Define the Gradio components
|
@@ -26,34 +28,15 @@ image = gr.Image(type='pil', label='Upload an Image')
|
|
26 |
label = gr.Label(label="Predictions")
|
27 |
examples = ['example1.jpeg', 'example2.jpeg', 'example3.jpeg'] # Replace with your example images
|
28 |
|
29 |
-
# Define
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
theme=theme
|
42 |
-
)
|
43 |
-
|
44 |
-
# Create the initial interface
|
45 |
-
intf = create_interface('default')
|
46 |
-
|
47 |
-
# Define a callback to update the theme
|
48 |
-
def update_theme(theme):
|
49 |
-
global intf
|
50 |
-
intf.close() # Close the current interface
|
51 |
-
intf = create_interface(theme) # Create a new interface with the selected theme
|
52 |
-
intf.launch(share=True, inline=False) # Launch the new interface
|
53 |
-
|
54 |
-
# Launch the initial interface
|
55 |
-
intf.launch(share=True, inline=False)
|
56 |
-
|
57 |
-
# Add a separate interface for theme selection
|
58 |
-
theme_intf = gr.Interface(fn=update_theme, inputs=theme_selector, outputs=None, live=True)
|
59 |
-
theme_intf.launch(share=True, inline=False)
|
|
|
8 |
model = load_model('race_prediction_model.h5')
|
9 |
|
10 |
# Define the categories based on your model's output
|
11 |
+
categories = [
|
12 |
+
'Black', 'Indian', 'Southeast Asian',
|
13 |
+
'East Asian', 'White', 'Middle Eastern', 'Latino_Hispanic'
|
14 |
+
] # Replace with your actual categories
|
15 |
|
16 |
# Define the function to classify images
|
17 |
def classify_image(img):
|
|
|
21 |
img_array /= 255.0
|
22 |
|
23 |
predictions = model.predict(img_array)
|
|
|
24 |
return {category: float(pred) for category, pred in zip(categories, predictions[0])}
|
25 |
|
26 |
# Define the Gradio components
|
|
|
28 |
label = gr.Label(label="Predictions")
|
29 |
examples = ['example1.jpeg', 'example2.jpeg', 'example3.jpeg'] # Replace with your example images
|
30 |
|
31 |
+
# Define the Gradio interface
|
32 |
+
intf = gr.Interface(
|
33 |
+
fn=classify_image,
|
34 |
+
inputs=image,
|
35 |
+
outputs=label,
|
36 |
+
title="Face to Race",
|
37 |
+
description="Upload an image to classify it based on the trained model.",
|
38 |
+
examples=examples
|
39 |
+
)
|
40 |
+
|
41 |
+
# Launch the interface
|
42 |
+
intf.launch(share=True, inline=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|