Samaskandan commited on
Commit
45c2287
·
verified ·
1 Parent(s): e5f534a

Upload 4 files

Browse files
capturerealtimedata.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.ensemble import RandomForestClassifier
5
+ from sklearn.preprocessing import StandardScaler
6
+ import joblib
7
+ import time
8
+
9
+ # Mock functions to simulate real-time data capture
10
+ def capture_eye_tracking_data():
11
+ fixation_duration = np.random.uniform(200, 400) # milliseconds (Typical fixation duration range)
12
+ saccadic_amplitude = np.random.uniform(1, 5) # degrees (Typical saccadic amplitude range)
13
+ saccadic_velocity = np.random.uniform(100, 400) # degrees/second (Typical saccadic velocity range)
14
+ return fixation_duration, saccadic_amplitude, saccadic_velocity
15
+
16
+ def capture_speech_data():
17
+ speech_rate = np.random.uniform(110, 160) # words per minute (Typical speech rate for adults)
18
+ pitch_variability = np.random.uniform(2, 4) # Hz (Typical pitch variability range)
19
+ return speech_rate, pitch_variability
20
+
21
+ # Load the pre-trained model and scaler
22
+ model = joblib.load(
23
+ 'C:/Users/somas/PycharmProjects/CreatingSyntheticDatasetsForEyeMovements/.venv/random_forest_model.pkl')
24
+ scaler = joblib.load('C:/Users/somas/PycharmProjects/CreatingSyntheticDatasetsForEyeMovements/.venv/scaler.pkl')
25
+
26
+ def main():
27
+ st.title("Real-Time ADHD Likelihood Prediction While Reading")
28
+
29
+ st.write("""
30
+ ### Read the passage below. Real-time data will be captured to predict the likelihood of ADHD.
31
+ """)
32
+
33
+ passage = """Once upon a time in a faraway land, there lived a wise old owl. The owl was known throughout the forest for its wisdom and kindness. It spent its days watching over the animals and offering advice to those in need. One day, a young fox approached the owl, seeking guidance on how to find its way home. The owl, with a gentle hoot, pointed the fox in the right direction, and the young fox trotted off happily. The owl watched as the fox disappeared into the woods, knowing that it had helped another creature find its path.
34
+
35
+ Several months passed, and the seasons began to change. As autumn arrived, the leaves turned golden and fell gently to the ground. The owl, now a bit older, still sat perched on its favorite branch, watching over the forest. One crisp morning, a lost rabbit came hopping along, tears in its eyes. The owl listened patiently as the rabbit explained how it had wandered too far from its burrow. With a knowing nod, the owl gave the rabbit some comforting words and pointed it toward the familiar trails leading back to its home.
36
+
37
+ Winter came soon after, bringing snow and cold winds to the forest. The wise owl, prepared for the harsh season, wrapped itself in its warm feathers. But even in the coldest of days, it continued to look after the forest dwellers. It guided the birds to safe nests and showed the deer where to find the last bits of food. Each act of kindness made the owl's heart feel fuller, despite the icy weather.
38
+
39
+ The months turned again, and spring brought new life to the forest. The trees blossomed, and flowers bloomed across the meadow. The owl, feeling rejuvenated, was visited by many animals that it had helped throughout the year. They came with gifts of gratitude and stories of how the owl’s wisdom had changed their lives. The owl, with a humble smile, listened to each story, grateful for the opportunity to have made a difference.
40
+
41
+ As the sun set on that beautiful spring day, the owl closed its eyes, feeling a deep sense of peace and contentment. It had spent its life in service to others, and now, surrounded by friends and the beauty of the forest, it felt truly at home."""
42
+ st.text_area("Passage", value=passage, height=200, max_chars=None)
43
+
44
+ # Initialize session state variables
45
+ if "capturing" not in st.session_state:
46
+ st.session_state.capturing = False
47
+ if "latest_data" not in st.session_state:
48
+ st.session_state.latest_data = None
49
+
50
+ # Define start and stop capture functions
51
+ def start_capture():
52
+ st.session_state.capturing = True
53
+
54
+ def stop_capture():
55
+ st.session_state.capturing = False
56
+
57
+ # Buttons for controlling data capture
58
+ col1, col2 = st.columns(2)
59
+ with col1:
60
+ if st.button("Start Capture"):
61
+ start_capture()
62
+ with col2:
63
+ if st.button("Stop Capture"):
64
+ stop_capture()
65
+
66
+ # Capturing data in real-time simulation
67
+ if st.session_state.capturing:
68
+ st.write("Capturing data... Please continue reading the passage above.")
69
+
70
+ fixation_duration, saccadic_amplitude, saccadic_velocity = capture_eye_tracking_data()
71
+ speech_rate, pitch_variability = capture_speech_data()
72
+
73
+ # Store the latest captured data in session state
74
+ st.session_state.latest_data = {
75
+ 'Fixation_Duration': fixation_duration,
76
+ 'Saccadic_Amplitude': saccadic_amplitude,
77
+ 'Saccadic_Velocity': saccadic_velocity,
78
+ 'Speech_Rate': speech_rate,
79
+ 'Pitch_Variability': pitch_variability
80
+ }
81
+
82
+ # Delay to mimic real-time data capture
83
+ time.sleep(1) # Simulate single capture for demonstration
84
+ stop_capture() # Automatically stop capture for demonstration purposes
85
+
86
+ # Display and predict based on the captured data
87
+ if st.session_state.latest_data:
88
+ st.write(f"Fixation Duration: {st.session_state.latest_data['Fixation_Duration']:.2f} ms")
89
+ st.write(f"Saccadic Amplitude: {st.session_state.latest_data['Saccadic_Amplitude']:.2f} degrees")
90
+ st.write(f"Saccadic Velocity: {st.session_state.latest_data['Saccadic_Velocity']:.2f} degrees/second")
91
+ st.write(f"Speech Rate: {st.session_state.latest_data['Speech_Rate']:.2f} words/min")
92
+ st.write(f"Pitch Variability: {st.session_state.latest_data['Pitch_Variability']:.2f} Hz")
93
+
94
+ # Prepare input data for prediction
95
+ input_data = pd.DataFrame([st.session_state.latest_data])
96
+
97
+ # Normalize the input data using the pre-fitted scaler
98
+ scaled_input_data = scaler.transform(input_data)
99
+
100
+ # Predict the likelihood of ADHD
101
+ prediction_probability = model.predict_proba(scaled_input_data)[0, 1]
102
+ threshold = 0.6 # Adjust based on model performance and validation
103
+ prediction = 1 if prediction_probability > threshold else 0
104
+
105
+ # Display the prediction and probability
106
+ st.write(f"**Prediction: {'ADHD Likely' if prediction == 1 else 'ADHD Unlikely'}**")
107
+ st.write(f"**Probability of ADHD: {prediction_probability:.2f}**")
108
+
109
+ if __name__ == "__main__":
110
+ main()
random_forest_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b0f2a37ea651460fd3ba283040b2c04e948b7d9de5799ca7efa05abd108a5471
3
+ size 1570889
requirements.txt ADDED
Binary file (1.76 kB). View file
 
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d561cf06c13c6e7dceb7a9d58c3c585d8a0e885e602577d86964e9f1cd686ac0
3
+ size 1135