File size: 3,106 Bytes
b641e9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3956ae6
 
 
 
 
 
b641e9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3fe776
b641e9a
 
 
 
bca8baf
b641e9a
3956ae6
87419c2
b641e9a
 
 
 
 
87419c2
 
 
b641e9a
 
 
bca8baf
b641e9a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Importing necessary libraries
import streamlit as st
import cv2
import json
import numpy as np
import threading 
import time
import pandas as pd
import mediapipe as mp
import tensorflow as tf
import matplotlib.pyplot as plt
import streamlit.components.v1 as com
from mediapipe_functions import *
import tempfile
from streamlit_lottie import st_lottie

st.set_page_config(
    page_title="Welcome to iSLR",
    page_icon="👋",
)

# st.markdown("""
# <style>
# .css-9s5bis.edgvbvh3
# {
#     visibility:hidden
# }
# .css-h5rgaw.egzxvld1
# {
#     visibility:hidden
# }
# </style>
# """, unsafe_allow_html=True)

st.sidebar.success("Select a demo above.")

st.title("ASL Sign Language Recognition App")

f=st.file_uploader("Please upload a video of a demo of ASL sign", type=['mp4'])

if f is not None:
    tfile = tempfile.NamedTemporaryFile(delete=False) 
    tfile.write(f.read())
    width = max(30, 0.01)
    side = max((100 - width) / 2, 0.01)

    _, container, _ = st.columns([side, width, side])
    container.video(data=tfile.name)
    # st.video(tfile.name)
    cap = cv2.VideoCapture(tfile.name)
    stframe = st.empty()
    
    # for local video file
    # cap = cv2.VideoCapture('videos\goodbye.mp4')
    
    final_landmarks=[]
    with mp_holistic.Holistic(min_detection_confidence=0.5, min_tracking_confidence=0.5) as holistic:
        while cap.isOpened():
            ret, frame = cap.read()
            if not ret:
                break
            image, results = mediapipe_detection(frame, holistic)
            draw(image, results)
            landmarks = extract_coordinates(results)
            final_landmarks.extend(landmarks)
    
    df1 = pd.DataFrame(final_landmarks,columns=['x','y','z'])
    
    # Necessary functions 
    ROWS_PER_FRAME = 543
    def load_relevant_data_subset(df):
        data_columns = ['x', 'y', 'z']
        data = df
        n_frames = int(len(data) / ROWS_PER_FRAME)
        data = data.values.reshape(n_frames, ROWS_PER_FRAME, len(data_columns))
        return data.astype(np.float32)
    
    # Loading data
    test_df = load_relevant_data_subset(df1)
    test_df = tf.convert_to_tensor(test_df)
    
    # Inference
    interpreter = tf.lite.Interpreter("models/model.tflite")
    prediction_fn = interpreter.get_signature_runner("serving_default")
    output = prediction_fn(inputs=test_df)
    sign = np.argmax(output["outputs"])
    
    sign_json=pd.read_json("sign_to_prediction_index_map.json",typ='series')
    sign_df=pd.DataFrame(sign_json)
    pred=sign_df.iloc[sign]
    st.write(pred)
    top_indices = np.argsort(output['outputs'])[::-1][:5]
    top_values = output['outputs'][top_indices]
    
    output_df = sign_df.iloc[top_indices]
    output_df['Value'] = top_values

    output_df.rename(columns = {0:'Index'}, inplace = True)
    output_df.drop(['Index'],1, inplace=True)
    st.write(output_df)
# callbacks : on_change, on_click
# com.iframe("https://embed.lottiefiles.com/animation/132349")
with open('assets/animations/14592-loader-cat.json') as source:
    animation=json.load(source)
st_lottie(animation, width=300)