Update app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ with st.sidebar:
|
|
42 |
# Set the desired width in pixels
|
43 |
image_width = 300
|
44 |
# Define the path to the image
|
45 |
-
image_path = "
|
46 |
# Display the image
|
47 |
st.image(image_path, width=image_width)
|
48 |
|
@@ -130,81 +130,64 @@ ENGAGED_STR = 'Engaged (Respect, Responsibility, Effort)'
|
|
130 |
PARTIALLY_ENGAGED_STR = 'Partially Engaged (about 50%)'
|
131 |
NOT_ENGAGED_STR = 'Not Engaged (less than 50%)'
|
132 |
|
133 |
-
import streamlit as st
|
134 |
-
import pandas as pd
|
135 |
-
|
136 |
def main():
|
137 |
st.title("Intervention Program Analysis")
|
138 |
|
139 |
-
|
|
|
140 |
|
141 |
if uploaded_file is not None:
|
142 |
try:
|
143 |
-
#
|
144 |
-
df = pd.read_excel(uploaded_file
|
145 |
-
|
146 |
-
#
|
147 |
-
def make_unique(column_names):
|
148 |
-
seen = {}
|
149 |
-
for i, column in enumerate(column_names):
|
150 |
-
if column not in seen:
|
151 |
-
seen[column] = 1
|
152 |
-
else:
|
153 |
-
seen[column] += 1
|
154 |
-
column_names[i] = f"{column}_{seen[column]}"
|
155 |
-
return column_names
|
156 |
-
|
157 |
-
df.columns = make_unique(list(df.columns))
|
158 |
-
|
159 |
-
# Step 3: Replace student names with initials
|
160 |
df = replace_student_names_with_initials(df)
|
161 |
|
162 |
-
# Step 4: Display the uploaded data
|
163 |
st.subheader("Uploaded Data")
|
164 |
-
st.write(df
|
165 |
|
166 |
-
#
|
167 |
if INTERVENTION_COLUMN not in df.columns:
|
168 |
st.error(f"Expected column '{INTERVENTION_COLUMN}' not found.")
|
169 |
return
|
170 |
|
171 |
-
#
|
172 |
df.columns = df.columns.str.strip()
|
173 |
|
174 |
-
#
|
175 |
intervention_stats = compute_intervention_statistics(df)
|
176 |
st.subheader("Intervention Session Statistics")
|
177 |
st.write(intervention_stats)
|
178 |
|
179 |
-
#
|
180 |
intervention_fig = plot_intervention_statistics(intervention_stats)
|
181 |
|
182 |
-
#
|
183 |
download_chart(intervention_fig, "intervention_statistics_chart.png")
|
184 |
|
185 |
-
#
|
186 |
student_metrics_df = compute_student_metrics(df)
|
187 |
st.subheader("Student Metrics")
|
188 |
st.write(student_metrics_df)
|
189 |
|
190 |
-
#
|
191 |
student_metrics_fig = plot_student_metrics(student_metrics_df)
|
192 |
|
193 |
-
#
|
194 |
download_chart(student_metrics_fig, "student_metrics_chart.png")
|
195 |
|
196 |
-
#
|
197 |
llm_input = prepare_llm_input(student_metrics_df)
|
198 |
|
199 |
-
#
|
200 |
with st.spinner("Generating AI analysis..."):
|
201 |
recommendations = prompt_response_from_hf_llm(llm_input)
|
202 |
|
203 |
-
# Step 15: Display AI Analysis
|
204 |
st.subheader("AI Analysis")
|
205 |
st.markdown(recommendations)
|
206 |
|
207 |
-
#
|
208 |
download_llm_output(recommendations, "llm_output.txt")
|
209 |
|
210 |
except Exception as e:
|
@@ -259,7 +242,6 @@ def compute_intervention_statistics(df):
|
|
259 |
stats_df = pd.DataFrame(stats)
|
260 |
return stats_df
|
261 |
|
262 |
-
|
263 |
def plot_intervention_statistics(intervention_stats):
|
264 |
# Create a stacked bar chart for sessions held and not held
|
265 |
sessions_held = intervention_stats['Intervention Sessions Held'].values[0]
|
@@ -281,8 +263,6 @@ def plot_intervention_statistics(intervention_stats):
|
|
281 |
|
282 |
return fig
|
283 |
|
284 |
-
|
285 |
-
|
286 |
def compute_student_metrics(df):
|
287 |
# Filter DataFrame for sessions where intervention happened
|
288 |
intervention_df = df[df[INTERVENTION_COLUMN].str.strip().str.lower() == 'yes']
|
@@ -294,12 +274,7 @@ def compute_student_metrics(df):
|
|
294 |
student_metrics = {}
|
295 |
|
296 |
for col in student_columns:
|
297 |
-
|
298 |
-
# Extract student name or initials, removing any suffixes added for uniqueness
|
299 |
-
student_name = re.match(r'Student Attendance \[(.+?)\]', col.split('_')[0]).group(1)
|
300 |
-
except AttributeError:
|
301 |
-
st.warning(f"Unexpected column name format: {col}. Skipping this column.")
|
302 |
-
continue
|
303 |
# Get the attendance data for the student
|
304 |
student_data = intervention_df[[col]].copy()
|
305 |
|
|
|
42 |
# Set the desired width in pixels
|
43 |
image_width = 300
|
44 |
# Define the path to the image
|
45 |
+
image_path = "/Users/cheynelevesseur/Desktop/Manual Library/Python_Code/LLM_Projects_1/intervention_analysis_app/mimtss_logo.png"
|
46 |
# Display the image
|
47 |
st.image(image_path, width=image_width)
|
48 |
|
|
|
130 |
PARTIALLY_ENGAGED_STR = 'Partially Engaged (about 50%)'
|
131 |
NOT_ENGAGED_STR = 'Not Engaged (less than 50%)'
|
132 |
|
|
|
|
|
|
|
133 |
def main():
|
134 |
st.title("Intervention Program Analysis")
|
135 |
|
136 |
+
# File uploader
|
137 |
+
uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx"])
|
138 |
|
139 |
if uploaded_file is not None:
|
140 |
try:
|
141 |
+
# Read the Excel file into a DataFrame
|
142 |
+
df = pd.read_excel(uploaded_file)
|
143 |
+
|
144 |
+
# Replace student names with initials
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
df = replace_student_names_with_initials(df)
|
146 |
|
|
|
147 |
st.subheader("Uploaded Data")
|
148 |
+
st.write(df # Display only the first four rows
|
149 |
|
150 |
+
# Ensure expected column is available
|
151 |
if INTERVENTION_COLUMN not in df.columns:
|
152 |
st.error(f"Expected column '{INTERVENTION_COLUMN}' not found.")
|
153 |
return
|
154 |
|
155 |
+
# Clean up column names
|
156 |
df.columns = df.columns.str.strip()
|
157 |
|
158 |
+
# Compute Intervention Session Statistics
|
159 |
intervention_stats = compute_intervention_statistics(df)
|
160 |
st.subheader("Intervention Session Statistics")
|
161 |
st.write(intervention_stats)
|
162 |
|
163 |
+
# Visualization for Intervention Session Statistics
|
164 |
intervention_fig = plot_intervention_statistics(intervention_stats)
|
165 |
|
166 |
+
# Add download button for Intervention Session Statistics chart
|
167 |
download_chart(intervention_fig, "intervention_statistics_chart.png")
|
168 |
|
169 |
+
# Compute Student Metrics
|
170 |
student_metrics_df = compute_student_metrics(df)
|
171 |
st.subheader("Student Metrics")
|
172 |
st.write(student_metrics_df)
|
173 |
|
174 |
+
# Visualization for Student Metrics
|
175 |
student_metrics_fig = plot_student_metrics(student_metrics_df)
|
176 |
|
177 |
+
# Add download button for Student Metrics chart
|
178 |
download_chart(student_metrics_fig, "student_metrics_chart.png")
|
179 |
|
180 |
+
# Prepare input for the language model
|
181 |
llm_input = prepare_llm_input(student_metrics_df)
|
182 |
|
183 |
+
# Generate Notes and Recommendations using Hugging Face LLM
|
184 |
with st.spinner("Generating AI analysis..."):
|
185 |
recommendations = prompt_response_from_hf_llm(llm_input)
|
186 |
|
|
|
187 |
st.subheader("AI Analysis")
|
188 |
st.markdown(recommendations)
|
189 |
|
190 |
+
# Add download button for LLM output
|
191 |
download_llm_output(recommendations, "llm_output.txt")
|
192 |
|
193 |
except Exception as e:
|
|
|
242 |
stats_df = pd.DataFrame(stats)
|
243 |
return stats_df
|
244 |
|
|
|
245 |
def plot_intervention_statistics(intervention_stats):
|
246 |
# Create a stacked bar chart for sessions held and not held
|
247 |
sessions_held = intervention_stats['Intervention Sessions Held'].values[0]
|
|
|
263 |
|
264 |
return fig
|
265 |
|
|
|
|
|
266 |
def compute_student_metrics(df):
|
267 |
# Filter DataFrame for sessions where intervention happened
|
268 |
intervention_df = df[df[INTERVENTION_COLUMN].str.strip().str.lower() == 'yes']
|
|
|
274 |
student_metrics = {}
|
275 |
|
276 |
for col in student_columns:
|
277 |
+
student_name = col.replace('Student Attendance [', '').replace(']', '').strip()
|
|
|
|
|
|
|
|
|
|
|
278 |
# Get the attendance data for the student
|
279 |
student_data = intervention_df[[col]].copy()
|
280 |
|