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|
| 6 |
+
import re
|
| 7 |
+
from gtts import gTTS
|
| 8 |
+
import tempfile
|
| 9 |
+
import base64
|
| 10 |
+
|
| 11 |
+
# Page configuration
|
| 12 |
+
st.set_page_config(
|
| 13 |
+
page_title="CICE 2.0 Healthcare Assessment Tool",
|
| 14 |
+
page_icon="π₯",
|
| 15 |
+
layout="wide",
|
| 16 |
+
initial_sidebar_state="expanded"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Custom CSS for styling
|
| 20 |
+
st.markdown("""
|
| 21 |
+
<style>
|
| 22 |
+
.main-header {
|
| 23 |
+
background: linear-gradient(90deg, #0066cc, #004499);
|
| 24 |
+
padding: 20px;
|
| 25 |
+
border-radius: 10px;
|
| 26 |
+
color: white;
|
| 27 |
+
text-align: center;
|
| 28 |
+
margin-bottom: 30px;
|
| 29 |
+
}
|
| 30 |
+
.assessment-box {
|
| 31 |
+
background: #f0fdf4;
|
| 32 |
+
padding: 20px;
|
| 33 |
+
border-radius: 10px;
|
| 34 |
+
border-left: 5px solid #059669;
|
| 35 |
+
margin: 20px 0;
|
| 36 |
+
}
|
| 37 |
+
.competency-item {
|
| 38 |
+
background: #f8fafc;
|
| 39 |
+
padding: 15px;
|
| 40 |
+
margin: 10px 0;
|
| 41 |
+
border-radius: 8px;
|
| 42 |
+
border-left: 4px solid #0891b2;
|
| 43 |
+
}
|
| 44 |
+
.score-display {
|
| 45 |
+
text-align: center;
|
| 46 |
+
padding: 30px;
|
| 47 |
+
background: white;
|
| 48 |
+
border-radius: 15px;
|
| 49 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 50 |
+
margin: 20px 0;
|
| 51 |
+
}
|
| 52 |
+
</style>
|
| 53 |
+
""", unsafe_allow_html=True)
|
| 54 |
+
|
| 55 |
+
# CICE Assessment Class
|
| 56 |
+
class CICE_Assessment:
|
| 57 |
+
def __init__(self, api_key):
|
| 58 |
+
if api_key:
|
| 59 |
+
genai.configure(api_key=api_key)
|
| 60 |
+
self.model = genai.GenerativeModel("gemini-2.0-flash-exp")
|
| 61 |
+
else:
|
| 62 |
+
self.model = None
|
| 63 |
+
|
| 64 |
+
def analyze_video(self, video_file):
|
| 65 |
+
"""Analyze video using the 18-point CICE 2.0 assessment"""
|
| 66 |
+
if not self.model:
|
| 67 |
+
raise Exception("Please provide a valid Google API key")
|
| 68 |
+
|
| 69 |
+
# Upload video to Gemini
|
| 70 |
+
temp_path = None
|
| 71 |
+
try:
|
| 72 |
+
# Save uploaded file to temporary location
|
| 73 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.webm') as tmp_file:
|
| 74 |
+
tmp_file.write(video_file.read())
|
| 75 |
+
temp_path = tmp_file.name
|
| 76 |
+
|
| 77 |
+
# Upload to Gemini
|
| 78 |
+
uploaded_file = genai.upload_file(path=temp_path, display_name="healthcare_interaction")
|
| 79 |
+
|
| 80 |
+
# Wait for processing
|
| 81 |
+
max_wait = 300
|
| 82 |
+
wait_time = 0
|
| 83 |
+
while uploaded_file.state.name == "PROCESSING" and wait_time < max_wait:
|
| 84 |
+
time.sleep(3)
|
| 85 |
+
wait_time += 3
|
| 86 |
+
uploaded_file = genai.get_file(uploaded_file.name)
|
| 87 |
+
|
| 88 |
+
if uploaded_file.state.name == "FAILED":
|
| 89 |
+
raise Exception("Video processing failed")
|
| 90 |
+
|
| 91 |
+
# The 18-point CICE 2.0 assessment prompt
|
| 92 |
+
prompt = """Analyze this healthcare team interaction video and provide a comprehensive assessment based on the CICE 2.0 instrument's 18 interprofessional competencies.
|
| 93 |
+
|
| 94 |
+
For EACH of the following 18 competencies, clearly state whether it was "OBSERVED" or "NOT OBSERVED" and provide specific examples with timestamps when possible:
|
| 95 |
+
|
| 96 |
+
1. IDENTIFIES FACTORS INFLUENCING HEALTH STATUS
|
| 97 |
+
2. IDENTIFIES TEAM GOALS FOR THE PATIENT
|
| 98 |
+
3. PRIORITIZES GOALS FOCUSED ON IMPROVING HEALTH OUTCOMES
|
| 99 |
+
4. VERBALIZES DISCIPLINE-SPECIFIC ROLE
|
| 100 |
+
5. OFFERS TO SEEK GUIDANCE FROM COLLEAGUES
|
| 101 |
+
6. COMMUNICATES ABOUT COST-EFFECTIVE AND TIMELY CARE
|
| 102 |
+
7. DIRECTS QUESTIONS TO OTHER HEALTH PROFESSIONALS BASED ON EXPERTISE
|
| 103 |
+
8. AVOIDS DISCIPLINE-SPECIFIC TERMINOLOGY
|
| 104 |
+
9. EXPLAINS DISCIPLINE-SPECIFIC TERMINOLOGY WHEN NECESSARY
|
| 105 |
+
10. COMMUNICATES ROLES AND RESPONSIBILITIES CLEARLY
|
| 106 |
+
11. ENGAGES IN ACTIVE LISTENING
|
| 107 |
+
12. SOLICITS AND ACKNOWLEDGES PERSPECTIVES
|
| 108 |
+
13. RECOGNIZES APPROPRIATE CONTRIBUTIONS
|
| 109 |
+
14. RESPECTFUL OF OTHER TEAM MEMBERS
|
| 110 |
+
15. COLLABORATIVELY WORKS THROUGH INTERPROFESSIONAL CONFLICTS
|
| 111 |
+
16. REFLECTS ON STRENGTHS OF TEAM INTERACTIONS
|
| 112 |
+
17. REFLECTS ON CHALLENGES OF TEAM INTERACTIONS
|
| 113 |
+
18. IDENTIFIES HOW TO IMPROVE TEAM EFFECTIVENESS
|
| 114 |
+
|
| 115 |
+
STRUCTURE YOUR RESPONSE AS FOLLOWS:
|
| 116 |
+
|
| 117 |
+
## OVERALL ASSESSMENT
|
| 118 |
+
Provide a brief overview of the team interaction quality and professionalism.
|
| 119 |
+
|
| 120 |
+
## DETAILED COMPETENCY EVALUATION
|
| 121 |
+
For each of the 18 competencies, format as:
|
| 122 |
+
|
| 123 |
+
Competency [number]: [name]
|
| 124 |
+
Status: [OBSERVED/NOT OBSERVED]
|
| 125 |
+
Evidence: [Specific examples from the video, or explanation of why it wasn't observed]
|
| 126 |
+
|
| 127 |
+
## STRENGTHS
|
| 128 |
+
List 3-5 key strengths observed in the team interaction
|
| 129 |
+
|
| 130 |
+
## AREAS FOR IMPROVEMENT
|
| 131 |
+
List 3-5 specific areas where the team could improve
|
| 132 |
+
|
| 133 |
+
## RECOMMENDATIONS
|
| 134 |
+
Provide 3-5 actionable recommendations for enhancing team collaboration and patient care
|
| 135 |
+
|
| 136 |
+
## FINAL SCORE
|
| 137 |
+
Competencies Observed: X/18
|
| 138 |
+
Overall Performance Level: [Exemplary/Proficient/Developing/Needs Improvement]"""
|
| 139 |
+
|
| 140 |
+
response = self.model.generate_content([uploaded_file, prompt])
|
| 141 |
+
return response.text
|
| 142 |
+
|
| 143 |
+
finally:
|
| 144 |
+
# Clean up temporary file
|
| 145 |
+
if temp_path and os.path.exists(temp_path):
|
| 146 |
+
os.unlink(temp_path)
|
| 147 |
+
|
| 148 |
+
def parse_assessment_score(assessment_text):
|
| 149 |
+
"""Parse the assessment text to extract score"""
|
| 150 |
+
try:
|
| 151 |
+
# Look for pattern like "X/18" in the text
|
| 152 |
+
import re
|
| 153 |
+
pattern = r'(\d+)/18'
|
| 154 |
+
match = re.search(pattern, assessment_text)
|
| 155 |
+
if match:
|
| 156 |
+
observed = int(match.group(1))
|
| 157 |
+
percentage = (observed / 18) * 100
|
| 158 |
+
|
| 159 |
+
if percentage >= 85:
|
| 160 |
+
level = "Exemplary"
|
| 161 |
+
color = "#059669"
|
| 162 |
+
elif percentage >= 70:
|
| 163 |
+
level = "Proficient"
|
| 164 |
+
color = "#0891b2"
|
| 165 |
+
elif percentage >= 50:
|
| 166 |
+
level = "Developing"
|
| 167 |
+
color = "#f59e0b"
|
| 168 |
+
else:
|
| 169 |
+
level = "Needs Improvement"
|
| 170 |
+
color = "#dc2626"
|
| 171 |
+
|
| 172 |
+
return observed, percentage, level, color
|
| 173 |
+
except:
|
| 174 |
+
pass
|
| 175 |
+
return 0, 0, "Unknown", "#6b7280"
|
| 176 |
+
|
| 177 |
+
def main():
|
| 178 |
+
# Header
|
| 179 |
+
st.markdown("""
|
| 180 |
+
<div class="main-header">
|
| 181 |
+
<h1>π₯ CICE 2.0 Healthcare Assessment Tool</h1>
|
| 182 |
+
<p>Analyze healthcare team interactions using the 18-point CICE 2.0 interprofessional competency framework</p>
|
| 183 |
+
</div>
|
| 184 |
+
""", unsafe_allow_html=True)
|
| 185 |
+
|
| 186 |
+
# Sidebar for API key
|
| 187 |
+
with st.sidebar:
|
| 188 |
+
st.header("π Configuration")
|
| 189 |
+
api_key = st.text_input(
|
| 190 |
+
"Google Gemini API Key",
|
| 191 |
+
type="password",
|
| 192 |
+
help="Enter your Google Gemini API key to analyze videos"
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
if api_key:
|
| 196 |
+
st.success("β
API Key configured")
|
| 197 |
+
else:
|
| 198 |
+
st.warning("β οΈ Please enter your Google Gemini API key")
|
| 199 |
+
|
| 200 |
+
st.markdown("---")
|
| 201 |
+
st.markdown("""
|
| 202 |
+
### π CICE 2.0 Competencies
|
| 203 |
+
1. Health Status Factors
|
| 204 |
+
2. Team Goals Identification
|
| 205 |
+
3. Goal Prioritization
|
| 206 |
+
4. Role Verbalization
|
| 207 |
+
5. Seeking Guidance
|
| 208 |
+
6. Cost-Effective Communication
|
| 209 |
+
7. Expertise-Based Questions
|
| 210 |
+
8. Avoiding Jargon
|
| 211 |
+
9. Explaining Terminology
|
| 212 |
+
10. Clear Role Communication
|
| 213 |
+
11. Active Listening
|
| 214 |
+
12. Soliciting Perspectives
|
| 215 |
+
13. Recognizing Contributions
|
| 216 |
+
14. Team Respect
|
| 217 |
+
15. Conflict Resolution
|
| 218 |
+
16. Strength Reflection
|
| 219 |
+
17. Challenge Reflection
|
| 220 |
+
18. Improvement Identification
|
| 221 |
+
""")
|
| 222 |
+
|
| 223 |
+
# Main content
|
| 224 |
+
col1, col2 = st.columns([2, 1])
|
| 225 |
+
|
| 226 |
+
with col1:
|
| 227 |
+
st.header("πΉ Upload Healthcare Team Video")
|
| 228 |
+
|
| 229 |
+
uploaded_file = st.file_uploader(
|
| 230 |
+
"Choose a video file",
|
| 231 |
+
type=['mp4', 'webm', 'avi', 'mov'],
|
| 232 |
+
help="Upload a video of healthcare team interaction for CICE 2.0 assessment"
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
if uploaded_file is not None:
|
| 236 |
+
st.success(f"β
Video uploaded: {uploaded_file.name}")
|
| 237 |
+
|
| 238 |
+
# Display video
|
| 239 |
+
st.video(uploaded_file)
|
| 240 |
+
|
| 241 |
+
# Analyze button
|
| 242 |
+
if st.button("π Analyze with CICE 2.0", type="primary"):
|
| 243 |
+
if not api_key:
|
| 244 |
+
st.error("β Please enter your Google Gemini API key in the sidebar")
|
| 245 |
+
else:
|
| 246 |
+
try:
|
| 247 |
+
assessor = CICE_Assessment(api_key)
|
| 248 |
+
|
| 249 |
+
with st.spinner("π€ Analyzing video with CICE 2.0 framework... This may take 1-2 minutes"):
|
| 250 |
+
# Reset file pointer
|
| 251 |
+
uploaded_file.seek(0)
|
| 252 |
+
assessment_result = assessor.analyze_video(uploaded_file)
|
| 253 |
+
|
| 254 |
+
# Parse score
|
| 255 |
+
observed, percentage, level, color = parse_assessment_score(assessment_result)
|
| 256 |
+
|
| 257 |
+
# Display summary
|
| 258 |
+
st.markdown(f"""
|
| 259 |
+
<div class="score-display">
|
| 260 |
+
<h2>CICE 2.0 Assessment Results</h2>
|
| 261 |
+
<div style="display: flex; justify-content: space-around; margin: 30px 0;">
|
| 262 |
+
<div style="text-align: center;">
|
| 263 |
+
<div style="font-size: 48px; font-weight: bold; color: {color};">{observed}/18</div>
|
| 264 |
+
<div style="color: #6b7280;">Competencies Observed</div>
|
| 265 |
+
</div>
|
| 266 |
+
<div style="text-align: center;">
|
| 267 |
+
<div style="font-size: 48px; font-weight: bold; color: {color};">{percentage:.0f}%</div>
|
| 268 |
+
<div style="color: #6b7280;">Overall Score</div>
|
| 269 |
+
</div>
|
| 270 |
+
</div>
|
| 271 |
+
<div style="text-align: center; padding: 20px; background: #f9fafb; border-radius: 10px;">
|
| 272 |
+
<div style="font-size: 24px; font-weight: bold; color: {color};">Performance Level: {level}</div>
|
| 273 |
+
</div>
|
| 274 |
+
</div>
|
| 275 |
+
""", unsafe_allow_html=True)
|
| 276 |
+
|
| 277 |
+
# Display detailed assessment
|
| 278 |
+
st.markdown('<div class="assessment-box">', unsafe_allow_html=True)
|
| 279 |
+
st.markdown("### π Detailed Assessment Report")
|
| 280 |
+
st.write(assessment_result)
|
| 281 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 282 |
+
|
| 283 |
+
# Download option
|
| 284 |
+
st.download_button(
|
| 285 |
+
label="π₯ Download Assessment Report",
|
| 286 |
+
data=assessment_result,
|
| 287 |
+
file_name=f"cice_assessment_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt",
|
| 288 |
+
mime="text/plain"
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
except Exception as e:
|
| 292 |
+
st.error(f"β Error during assessment: {str(e)}")
|
| 293 |
+
|
| 294 |
+
with col2:
|
| 295 |
+
st.header("βΉοΈ About CICE 2.0")
|
| 296 |
+
st.markdown("""
|
| 297 |
+
The **Collaborative Interprofessional Team Environment (CICE) 2.0** instrument evaluates healthcare team interactions across 18 key competencies.
|
| 298 |
+
|
| 299 |
+
### π― Purpose
|
| 300 |
+
- Assess interprofessional collaboration
|
| 301 |
+
- Identify team strengths
|
| 302 |
+
- Highlight improvement areas
|
| 303 |
+
- Enhance patient care quality
|
| 304 |
+
|
| 305 |
+
### π Scoring Levels
|
| 306 |
+
- **Exemplary** (85-100%): Outstanding collaboration
|
| 307 |
+
- **Proficient** (70-84%): Good teamwork
|
| 308 |
+
- **Developing** (50-69%): Needs improvement
|
| 309 |
+
- **Needs Improvement** (<50%): Significant gaps
|
| 310 |
+
|
| 311 |
+
### π Getting Started
|
| 312 |
+
1. Enter your Google Gemini API key
|
| 313 |
+
2. Upload a healthcare team video
|
| 314 |
+
3. Click "Analyze with CICE 2.0"
|
| 315 |
+
4. Review detailed results
|
| 316 |
+
5. Download assessment report
|
| 317 |
+
""")
|
| 318 |
+
|
| 319 |
+
if __name__ == "__main__":
|
| 320 |
+
main()
|