Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import from_pretrained_keras
|
| 3 |
-
import numpy as np
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def predict_model(x_, model_1, model_2):
|
| 13 |
-
pred = model_1.predict(x_.reshape(x_.shape[0], 48, 48, 1))
|
| 14 |
-
pred_eth=model_2.predict(x_.reshape(x_.shape[0], 48, 48, 1))
|
| 15 |
-
pred_gender=[round(pred[0][x][0]) for x in range(x_.shape[0])]
|
| 16 |
-
pred_age=[round(pred[1][x][0]) for x in range(x_.shape[0])]
|
| 17 |
-
pred_eth=[np.argmax(pred_eth[x]) for x in range(x_.shape[0])]
|
| 18 |
-
|
| 19 |
-
return pred_gender, pred_age, pred_eth
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
def image_classifier(input_img):
|
| 23 |
-
gray=rgb2gray(input_img)
|
| 24 |
-
g,a,e=predict_model(gray.reshape(1, 48, 48, 1),reloaded_model,reloaded_model_eth)
|
| 25 |
-
|
| 26 |
-
dict_gender={ 0: 'Male', 1:'Female'}
|
| 27 |
-
g=dict_gender[g]
|
| 28 |
-
dict_eth={0:"White", 1:"Black", 2:"Asian", 3:"Indian", 4:"Hispanic"}
|
| 29 |
-
e=dict_eth[e]
|
| 30 |
-
return ("The predicted gender is {} , predicted age is {} and the predicted ethnicity is {}".format(g,a,e))
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
iface = gr.Interface(
|
| 36 |
-
image_classifier,
|
| 37 |
-
gr.inputs.Image(shape=(48, 48),),
|
| 38 |
-
outputs=['text']
|
| 39 |
-
capture_session=True,
|
| 40 |
-
interpretation="default",
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
iface.launch(share=True)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def greet(name):
|
| 4 |
+
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|