import subprocess # Ensure setup.sh is executable and then run it using bash subprocess.run(['chmod', '+x', 'setup.sh']) subprocess.run(['bash', 'setup.sh'], check=True) import streamlit as st import os import numpy as np import torchaudio import tensorflow as tf from tensorflow.keras.models import load_model import tensorflow_hub as hub import time import psutil import streamlit.components.v1 as components import random # model_path = 'C:/Users/giris/Downloads/AutismUI/TrillsonFeature_model' # m = hub.load(model_path) m = hub.KerasLayer('https://tfhub.dev/google/nonsemantic-speech-benchmark/trillsson4/1') class TransformerEncoder(tf.keras.layers.Layer): def __init__(self, embed_dim, num_heads, ff_dim, rate=0.01, **kwargs): super(TransformerEncoder, self).__init__(**kwargs) self.embed_dim = embed_dim self.num_heads = num_heads self.ff_dim = ff_dim self.rate = rate self.att = tf.keras.layers.MultiHeadAttention(num_heads=num_heads, key_dim=embed_dim) self.ffn = tf.keras.Sequential([tf.keras.layers.Dense(ff_dim, activation="relu"), tf.keras.layers.Dense(embed_dim)]) self.layernorm1 = tf.keras.layers.LayerNormalization(epsilon=1e-6) self.layernorm2 = tf.keras.layers.LayerNormalization(epsilon=1e-6) self.dropout1 = tf.keras.layers.Dropout(rate) self.dropout2 = tf.keras.layers.Dropout(rate) def call(self, inputs, training=False): attn_output = self.att(inputs, inputs) attn_output = self.dropout1(attn_output, training=training) out1 = self.layernorm1(inputs + attn_output) ffn_output = self.ffn(out1) ffn_output = self.dropout2(ffn_output, training=training) return self.layernorm2(out1 + ffn_output) def get_config(self): config = super(TransformerEncoder, self).get_config() config.update({ 'embed_dim': self.embed_dim, 'num_heads': self.num_heads, 'ff_dim': self.ff_dim, 'rate': self.rate }) return config model = load_model('C:/Users/giris/Downloads/AutismUI/autism_detection_model3.h5', custom_objects={'TransformerEncoder': TransformerEncoder}) def extract_features(path): sample_rate = 16000 array, fs = torchaudio.load(path) array = np.array(array) if array.shape[0] > 1: array = np.mean(array, axis=0, keepdims=True) embeddings = m(array)['embedding'] embeddings.shape.assert_is_compatible_with([None, 1024]) embeddings = np.squeeze(np.array(embeddings), axis=0) return embeddings # st.markdown('Streamlit is **_really_ cool**.') st.markdown('Neu RO: An Application for Code-Switched Autism Detection in Children', unsafe_allow_html=True) # def set_background(): # # HTML code with CSS styling for background image # page_bg_img = ''' # # ''' # st.markdown(page_bg_img, unsafe_allow_html=True) # # Call the function to set background image # set_background() # def random_color(): # r = random.randint(0, 255) # g = random.randint(0, 255) # b = random.randint(0, 255) # return f'rgb({r}, {g}, {b})' # text = "NeuRO: An Application for Code-Switched Autism Detection in Children" # words = text.split() # styled_text = "" # for word in words: # color = random_color() # styled_text += f'{word} ' # st.markdown(styled_text, unsafe_allow_html=True) #st.title('NeuRO: An Application for Code-Switched Autism Detection in Children') # option = st.radio("Choose an option:", ("Upload an audio file", "Record audio")) option = st.radio("**Choose an option:**", ["Upload an audio file", "Record audio"]) if option == "Upload an audio file": uploaded_file = st.file_uploader("Upload an audio file (.wav)", type=["wav"]) if uploaded_file is not None: start_time = time.time() # Record start time with st.spinner('Extracting features...'): # Process the uploaded file with open("temp_audio.wav", "wb") as f: f.write(uploaded_file.getbuffer()) features = extract_features("temp_audio.wav") os.remove("temp_audio.wav") # Display prediction probabilities prediction = model.predict(np.expand_dims(features, axis=0)) autism_probability = prediction[0][1] normal_probability = prediction[0][0] st.subheader("Prediction Probabilities:") if autism_probability > normal_probability: st.markdown( f'