Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +56 -0
- keypoint_model.h5 +3 -0
- requirements.txt +10 -0
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# streamlit_app.py
|
| 2 |
+
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pandas as pd
|
| 6 |
+
from keras.models import load_model
|
| 7 |
+
from PIL import Image, ImageDraw
|
| 8 |
+
import io
|
| 9 |
+
|
| 10 |
+
# Load the trained model
|
| 11 |
+
model = load_model('keypoint_model.h5')
|
| 12 |
+
|
| 13 |
+
def load_image(image):
|
| 14 |
+
image = Image.open(image).convert('L') # Convert to grayscale
|
| 15 |
+
image = image.resize((96, 96)) # Resize to match model input
|
| 16 |
+
image_array = np.array(image)
|
| 17 |
+
image_array = image_array / 255.0 # Normalize
|
| 18 |
+
return image_array.reshape(-1, 96, 96, 1) # Reshape for model input
|
| 19 |
+
|
| 20 |
+
def draw_keypoints(image, keypoints):
|
| 21 |
+
# Draw keypoints on the image
|
| 22 |
+
draw = ImageDraw.Draw(image)
|
| 23 |
+
for (x, y) in keypoints:
|
| 24 |
+
draw.ellipse((x - 3, y - 3, x + 3, y + 3), fill='red') # Draw a circle for each keypoint
|
| 25 |
+
return image
|
| 26 |
+
|
| 27 |
+
# Title of the app
|
| 28 |
+
st.title("Keypoint Prediction App")
|
| 29 |
+
|
| 30 |
+
# Upload an image
|
| 31 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 32 |
+
|
| 33 |
+
if uploaded_file is not None:
|
| 34 |
+
# Load and preprocess the image
|
| 35 |
+
image = load_image(uploaded_file)
|
| 36 |
+
|
| 37 |
+
# Display the uploaded image
|
| 38 |
+
original_image = Image.open(uploaded_file).convert('L').resize((96, 96)) # Convert and resize for displaying
|
| 39 |
+
st.image(original_image, caption='Uploaded Image.', use_column_width=True)
|
| 40 |
+
|
| 41 |
+
# Make predictions
|
| 42 |
+
if st.button("Predict"):
|
| 43 |
+
predictions = model.predict(image)
|
| 44 |
+
# Reshape predictions to (15, 2) for x and y coordinates
|
| 45 |
+
keypoints = predictions.reshape(-1, 2)
|
| 46 |
+
|
| 47 |
+
# Draw keypoints on the original image
|
| 48 |
+
keypoint_image = draw_keypoints(original_image.copy(), keypoints)
|
| 49 |
+
|
| 50 |
+
# Display the image with keypoints
|
| 51 |
+
st.image(keypoint_image, caption='Image with Predicted Keypoints', use_column_width=True)
|
| 52 |
+
|
| 53 |
+
# Display the keypoints
|
| 54 |
+
st.write("Predicted Keypoints:")
|
| 55 |
+
for i, (x, y) in enumerate(keypoints):
|
| 56 |
+
st.write(f"Keypoint {i+1}: (X: {x:.2f}, Y: {y:.2f})")
|
keypoint_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ae40978ed7325ae8ea1c953ffcab3b3d41fb7a97bd4b5c63cd03bfb446fcf85b
|
| 3 |
+
size 3424376
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
tensorflow
|
| 3 |
+
opencv-python
|
| 4 |
+
scikit-learn
|
| 5 |
+
torch
|
| 6 |
+
torchvision
|
| 7 |
+
matplotlib
|
| 8 |
+
transformers
|
| 9 |
+
sentencepiece
|
| 10 |
+
plotly
|