Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,23 +12,18 @@ import os
|
|
| 12 |
|
| 13 |
model_url = "https://huggingface.co/foryahasake/act-h5/resolve/main/bestXceptionPlusData.h5"
|
| 14 |
model_filename = "bestXceptionPlusData.h5"
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
print("Downloading model file...")
|
| 18 |
-
response = requests.get(model_url)
|
| 19 |
-
with open(model_filename, "wb") as f:
|
| 20 |
-
f.write(response.content)
|
| 21 |
-
print("Model downloaded successfully!")
|
| 22 |
-
|
| 23 |
-
model = tf_keras.models.load_model(model_filename, compile=False, custom_objects={'tf': tf})
|
| 24 |
|
| 25 |
def inference(inp):
|
| 26 |
if len(inp.shape) == 3: # If the image is colored
|
| 27 |
pil_gray = cv2.cvtColor(inp, cv2.COLOR_RGB2GRAY)
|
| 28 |
else:
|
| 29 |
pil_gray = inp
|
|
|
|
| 30 |
|
| 31 |
-
model_input =
|
| 32 |
model_input = np.expand_dims(model_input, axis=-1) # Add channel dimension
|
| 33 |
model_input = np.expand_dims(model_input, axis=0) # Add batch dimension
|
| 34 |
|
|
@@ -42,4 +37,4 @@ def inference(inp):
|
|
| 42 |
return predicted_emotion
|
| 43 |
|
| 44 |
demo = gr.Interface(fn=inference, inputs="image", outputs="label")
|
| 45 |
-
demo.launch()
|
|
|
|
| 12 |
|
| 13 |
model_url = "https://huggingface.co/foryahasake/act-h5/resolve/main/bestXceptionPlusData.h5"
|
| 14 |
model_filename = "bestXceptionPlusData.h5"
|
| 15 |
+
from huggingface_hub import from_pretrained_keras
|
| 16 |
|
| 17 |
+
model = from_pretrained_keras( "foryahasake/act-h5")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def inference(inp):
|
| 20 |
if len(inp.shape) == 3: # If the image is colored
|
| 21 |
pil_gray = cv2.cvtColor(inp, cv2.COLOR_RGB2GRAY)
|
| 22 |
else:
|
| 23 |
pil_gray = inp
|
| 24 |
+
resized_img = cv2.resize(pil_gray, (48,48), interpolation=cv2.INTER_CUBIC)
|
| 25 |
|
| 26 |
+
model_input = resized_img / 255.0
|
| 27 |
model_input = np.expand_dims(model_input, axis=-1) # Add channel dimension
|
| 28 |
model_input = np.expand_dims(model_input, axis=0) # Add batch dimension
|
| 29 |
|
|
|
|
| 37 |
return predicted_emotion
|
| 38 |
|
| 39 |
demo = gr.Interface(fn=inference, inputs="image", outputs="label")
|
| 40 |
+
demo.launch()
|