SreekarB commited on
Commit
d0f2f4f
·
verified ·
1 Parent(s): e0eefc3

Upload simple_casl_app.py

Browse files
Files changed (1) hide show
  1. simple_casl_app.py +30 -296
simple_casl_app.py CHANGED
@@ -75,7 +75,7 @@ def process_file(file):
75
  except Exception as e:
76
  return f"Error reading file: {str(e)}"
77
 
78
- def analyze_transcript(file, age, gender):
79
  """Simple CASL analysis"""
80
  if file is None:
81
  return "Please upload a transcript file first."
@@ -85,264 +85,23 @@ def analyze_transcript(file, age, gender):
85
  if transcript.startswith("Error") or transcript.startswith("Please"):
86
  return transcript
87
 
88
- # Provide the instructions for analyzing the transcript
89
- instructions = f"""
90
-
91
-
92
-
93
- Each domain from the CASL-2 framework can be analyzed using the sample:
94
-
95
- Lexical/Semantic Skills:
96
-
97
- This category focuses on vocabulary knowledge, word meanings, and the ability to use words contextually. It measures both receptive and expressive language abilities related to word use.
98
-
99
- Key Subtests:
100
-
101
- Antonyms: Identifying words with opposite meanings.
102
- Synonyms: Identifying words with similar meanings.
103
- Idiomatic Language: Understanding and interpreting idioms and figurative language.
104
-
105
- Evaluate vocabulary diversity (type-token ratio).
106
- Note word-finding difficulties, incorrect word choices, or over-reliance on fillers (e.g., “like,” “stuff”).
107
- Assess use of specific vs. vague language (e.g., "car" vs. "sedan").
108
-
109
- Syntactic Skills:
110
-
111
- This category evaluates understanding and use of grammar and sentence structure. It focuses on the ability to comprehend and produce grammatically correct sentences.
112
-
113
- Key Subtests:
114
-
115
- Sentence Expression: Producing grammatically correct sentences based on prompts.
116
- Grammaticality Judgment: Identifying whether a sentence is grammatically correct.
117
-
118
- Examine sentence structure for grammatical accuracy.
119
- Identify errors in verb tense, subject-verb agreement, or sentence complexity.
120
- Note the use of clauses, conjunctions, and varied sentence types.
121
-
122
-
123
- Supralinguistic Skills:
124
-
125
- This subcategory assesses higher-level language skills that go beyond literal meanings, such as understanding implied meanings, sarcasm, and complex verbal reasoning.
126
-
127
- Key Subtests:
128
-
129
- Inferences: Understanding information that is not explicitly stated.
130
- Meaning from Context: Deriving meaning from surrounding text or dialogue.
131
- Nonliteral Language: Interpreting figurative language, such as metaphors or irony
132
-
133
- Look for use or understanding of figurative language, idioms, or humor.
134
- Assess ability to handle ambiguous or implied meanings in context.
135
- Identify advanced language use for abstract or hypothetical ideas.
136
-
137
-
138
- Pragmatic Skills(focus less on this as it is not typically necessary for the age range you will be dealing with):
139
- This category measures the ability to use language effectively in social contexts. It evaluates understanding of conversational rules, turn-taking, and adapting communication to different social situations.
140
-
141
- Key Subtests:
142
-
143
- Pragmatic Language Test: Assessing appropriateness of responses in social scenarios.
144
-
145
-
146
- Observe turn-taking, topic maintenance, and conversational appropriateness.
147
- Note use of politeness, tone, or adapting language to the listener.
148
- Evaluate narrative coherence in storytelling or recounting events.
149
-
150
-
151
- Quantitative Analysis:
152
- Count errors (e.g., grammatical, lexical) and divide by total utterances to calculate error rates.
153
- Measure Mean Length of Utterance (MLU) to gauge syntactic complexity.
154
- Count the variety of unique words for vocabulary richness.
155
-
156
-
157
- Qualitative Analysis:
158
- Assess the appropriateness and sophistication of responses for the individual’s age.
159
- Evaluate overall fluency, coherence, and adaptability in communication.
160
- 1. Lexical/Semantic Analysis
161
- Objective: Evaluate vocabulary diversity, word meaning, and contextual usage.
162
- LLM Process:
163
-
164
- Word Diversity:
165
- Calculate the type-token ratio (TTR): Divide the number of unique words by the total number of words to estimate vocabulary richness.
166
- Identify repetition and overuse of basic words.
167
- Word Appropriateness:
168
- Analyze context to determine if words are used accurately (e.g., "big" for "large" vs. incorrect substitutions).
169
- Idiomatic Language:
170
- Detect use of idioms, metaphors, or figurative expressions.
171
- Assess whether these expressions are used and interpreted correctly within the speech.
172
- Scoring:
173
-
174
- Assign scores based on TTR thresholds and the presence of appropriately used advanced vocabulary or idiomatic language.
175
- 2. Syntactic Analysis
176
- Objective: Assess grammatical accuracy, sentence complexity, and variety.
177
- LLM Process:
178
-
179
- Grammar Checking:
180
- Identify grammatical errors (e.g., incorrect verb tense, subject-verb disagreement, missing articles).
181
- Sentence Complexity:
182
- Calculate the mean length of utterance (MLU): Average the number of morphemes per sentence.
183
- Count clauses, conjunctions, and use of complex structures (e.g., relative clauses).
184
- Error Patterns:
185
- Note recurring syntactic errors or simplified constructions indicative of developmental or functional delays.
186
- Scoring:
187
-
188
- Base scores on error frequency, MLU, and the proportion of complex vs. simple sentences.
189
- 3. Supralinguistic Analysis
190
- Objective: Evaluate understanding and use of abstract, implied, or nonliteral language.
191
- LLM Process:
192
-
193
- Inference Detection:
194
- Analyze whether the speaker makes logical inferences or responds appropriately to indirect prompts (e.g., "Why do you think they did that?" requiring contextual reasoning).
195
- Nonliteral Language:
196
- Detect use or interpretation of figurative expressions, idioms, or sarcasm.
197
- Contextual Adaptation:
198
- Assess whether the speaker adjusts their language based on the situation or implied meaning.
199
- Scoring:
200
-
201
- Assign points for accurate interpretations of implied meanings and use of nonliteral language.
202
- 4. Pragmatic Analysis
203
- Objective: Assess social communication and appropriateness in interactions.
204
-
205
-
206
- LLM Process:
207
-
208
- Turn-Taking and Topic Maintenance:
209
- Evaluate whether the speaker follows conversational rules, including turn-taking and staying on topic.
210
- Social Cues:
211
- Analyze how well the speaker uses language to match the context (e.g., formal vs. informal speech).
212
- Clarity and Politeness:
213
- Assess the appropriateness of language for the audience and situation (e.g., clarity, tone, politeness).
214
- Scoring:
215
-
216
- Base scores on observed appropriateness and adherence to conversational norms.
217
- 5. Overall Scoring
218
- Objective: Aggregate scores for all categories to estimate a composite language ability.
219
- LLM Process:
220
-
221
- Normalize subcategory scores based on predefined thresholds (e.g., raw scores from lexical, syntactic, supralinguistic, and pragmatic categories).
222
- Combine normalized scores to calculate an estimated General Language Ability Index (GLAI).
223
- Implementation Workflow
224
- Input:
225
- Provide the LLM with a transcribed spontaneous speech sample.
226
- Include metadata (e.g., speaker’s age, context of the conversation).
227
- Processing:
228
- Use predefined scoring rubrics to analyze lexical, syntactic, supralinguistic, and pragmatic features in the transcript.
229
- Output:
230
- Generate scores for each subcategory.
231
- Offer a detailed breakdown explaining how each score was derived.
232
- Summarize results with an estimated composite score and percentile rank.
233
-
234
-
235
- The CASL-2 provides descriptive scores for each subcategory and subtest to help interpret an individual's performance relative to age-based norms. These descriptive scores are based on the standard scores and are typically categorized into qualitative performance levels. Here’s an overview of how the descriptive scores are generally aligned for each subcategory and subtest:
236
-
237
- Descriptive Score Levels
238
- Each subcategory or subtest score typically falls into one of these descriptive ranges based on the standard score:
239
-
240
- Standard Score Range Descriptive Label
241
- 131 and above Very Superior
242
- 121–130 Superior
243
- 111–120 Above Average
244
- 90–110 Average
245
- 80–89 Below Average
246
- 70–79 Poor
247
- Below 70 Very Poor
248
- Descriptive Scores for Each Subcategory
249
- 1. Lexical/Semantic
250
- Reflects vocabulary knowledge, word usage, and ability to interpret word relationships.
251
- Descriptive labels are based on scores from subtests like Antonyms, Synonyms, and Idiomatic Language.
252
- 2. Syntactic
253
- Evaluates grammar and sentence structure understanding.
254
- Descriptive scores use results from subtests such as Sentence Expression and Grammaticality Judgment.
255
- 3. Supralinguistic
256
- Represents higher-order language comprehension, such as nonliteral and abstract meanings.
257
- Descriptive labels are derived from subtests like Inferences, Meaning from Context, and Nonliteral Language.
258
- 4. Pragmatic
259
- Measures social language use, including conversational appropriateness and adaptability.
260
- Descriptive scores come from the Pragmatic Language Test.
261
- 5. General Language Ability Index (GLAI)
262
- Composite score representing overall spoken language competence.
263
- Combines scaled scores from various subtests into one standard score, interpreted using the same descriptive range.
264
- Percentile Ranks
265
- In addition to descriptive scores, CASL-2 provides percentile ranks to indicate the proportion of individuals in the normative sample who scored lower than the test-taker. For example:
266
-
267
- A standard score of 100 corresponds to the 50th percentile (average performance).
268
- A score of 85 corresponds to the 16th percentile (below average).
269
 
 
 
270
  """
271
-
272
- # Format the answer
273
- answer_format = f"""
274
- Template for LLM Output: CASL-2 Analysis from Spontaneous Speech Sample
275
- 1. Introduction
276
- Provide a brief overview of the analysis, including context and objectives.
277
- Example:
278
- "This analysis evaluates the spoken language abilities of the individual based on a transcribed spontaneous speech sample. The results are categorized into the CASL-2 subcategories: Lexical/Semantic, Syntactic, Supralinguistic, Pragmatic, and Overall Language Ability."
279
-
280
- 2. Lexical/Semantic Analysis
281
- Describe findings related to vocabulary, word meanings, and contextual usage.
282
-
283
- Word Diversity (Type-Token Ratio):
284
- Example: The speaker used 80 unique words out of 200 total words, resulting in a TTR of 0.4, indicating moderate vocabulary richness.
285
-
286
- Word Appropriateness:
287
- Example: Most words were used correctly within context, though advanced vocabulary or synonyms were limited.
288
-
289
- Idiomatic and Figurative Language:
290
- Example: No idiomatic expressions or figurative language were observed.
291
-
292
- Score: X/5
293
- 3. Syntactic Analysis
294
- Evaluate grammatical accuracy, sentence complexity, and structure.
295
-
296
- Grammatical Accuracy:
297
- Example: The speech contained 3 grammatical errors, such as incorrect verb tense usage ("I goed to the park").
298
-
299
- Sentence Complexity (Mean Length of Utterance):
300
- Example: The mean length of utterance (MLU) was 5.2 words, indicating a preference for simple sentences.
301
-
302
- Error Patterns:
303
- Example: Frequent omissions of articles and auxiliary verbs.
304
-
305
- Score: X/5
306
- 4. Supralinguistic Analysis
307
- Assess abstract and nonliteral language skills.
308
-
309
- Inference Making:
310
- Example: The speaker demonstrated minimal ability to infer meaning, as responses were literal and lacked contextual reasoning.
311
-
312
- Nonliteral Language:
313
- Example: No use or understanding of idioms, metaphors, or sarcasm was observed.
314
-
315
- Contextual Adaptation:
316
- Example: The speaker’s responses were appropriate to the conversation but lacked depth.
317
-
318
- Score: X/5
319
- 5. Pragmatic Analysis
320
- Examine social communication skills and conversational appropriateness.
321
-
322
- Turn-Taking:
323
- Example: The speaker effectively took turns but occasionally interrupted the conversational flow.
324
-
325
- Topic Maintenance:
326
- Example: The speaker maintained the topic but struggled with cohesive transitions.
327
-
328
- Social Appropriateness:
329
- Example: Responses were contextually appropriate but lacked expressive variation.
330
-
331
- Score: X/5
332
- 6. Overall Language Ability
333
- Summarize the composite score and provide insights.
334
 
335
- Composite Score (Estimated):
336
- Example: The composite score, derived from subcategory averages, is 3.0/5, indicating below-average language abilities relative to peers.
337
-
338
- Percentile Rank:
339
- Example: Based on performance, the speaker falls in the 30th percentile for their age group.
340
 
341
- Key Strengths:
342
- Example: The speaker exhibited strong topic maintenance and grammatical accuracy for simple sentences.
343
 
344
- Areas for Improvement:
345
- Example: Vocabulary diversity, sentence complexity, and inference-making skills require development.
346
 
347
  Please provide a CASL analysis including:
348
 
@@ -354,51 +113,20 @@ Template for LLM Output: CASL-2 Analysis from Spontaneous Speech Sample
354
 
355
  2. CASL SKILLS ASSESSMENT:
356
  - Lexical/Semantic Skills (Standard Score, Percentile, Level)
357
- - Syntactic Skills (Standard Score, Percentile, Level)
358
- - Supralinguistic Skills (Standard Score, Percentile, Level)
359
-
360
- 3. TREATMENT RECOMMENDATIONS:
361
- - List 3-5 specific intervention strategies
362
-
363
- 4. CLINICAL SUMMARY:
364
- - Brief explanation of findings and prognosis
365
-
366
- Use exact quotes from the transcript as evidence.
367
- Provide realistic standard scores (70-130 range, mean=100).
368
- """
369
-
370
- prompt = f"""
371
-
372
-
373
- You are a speech pathologist, a healthcare professional who specializes in evaluating, diagnosing, and treating communication disorders, including speech, language, cognitive-communication, voice, swallowing, and fluency disorders. Your role is to help patients improve their speech and communication skills through various therapeutic techniques and exercises.
374
-
375
- In this scenario, you will be working with a patient who has the following speech disorder or issue:
376
-
377
- Autism Spectrum Disorder - Demographics Patient: {age}-year-old {gender}
378
 
379
- A speech-language pathologist (SLP) working in schools plays a vital role in supporting students with autism spectrum disorder (ASD). These professionals focus on helping students develop the communication skills they need to succeed academically, socially, and emotionally. Communication challenges are a common characteristic of ASD, and SLPs are uniquely equipped to address them with specialized knowledge and strategies.
 
380
 
381
- SLPs working with students with ASD begin by assessing their communication abilities, including their use of verbal and nonverbal language. This evaluation may involve observing how the student interacts with peers and teachers, understanding their use of gestures, facial expressions, or other forms of communication, and identifying areas for improvement. Based on the assessment, the SLP creates an individualized treatment plan tailored to the student’s specific needs.
 
382
 
383
- Interventions often focus on improving social communication skills, such as taking turns in conversation, understanding and using eye contact, recognizing emotions in others, and maintaining appropriate topics during discussions. For students with limited verbal abilities, the SLP may introduce augmentative and alternative communication (AAC) tools, such as picture exchange systems or speech-generating devices, to help them express themselves effectively.
384
-
385
- Here is a sample dialogue between you and the patient:
386
-
387
- <dialogue>
388
-
389
- TRANSCRIPT:
390
- {transcript}
391
- </dialogue>
392
-
393
- Based on the information provided, please do the following:
394
-
395
- {instructions}
396
- Do this using {answer_format}
397
-
398
- Remember, your goal is to provide a comprehensive and supportive therapy experience for the patient, helping them to improve their speech and communication skills and build their confidence in the process. Use your expertise and empathy to guide them through this journey.
399
 
400
- """
401
-
402
  # Get analysis from Claude API
403
  result = call_claude_api(prompt)
404
  return result
@@ -431,6 +159,12 @@ with gr.Blocks(title="Simple CASL Analysis", theme=gr.themes.Soft()) as app:
431
  value="male"
432
  )
433
 
 
 
 
 
 
 
434
  analyze_btn = gr.Button(
435
  "🔍 Analyze Transcript",
436
  variant="primary"
@@ -449,7 +183,7 @@ with gr.Blocks(title="Simple CASL Analysis", theme=gr.themes.Soft()) as app:
449
  # Connect the analyze button
450
  analyze_btn.click(
451
  analyze_transcript,
452
- inputs=[file_upload, age, gender],
453
  outputs=[output]
454
  )
455
 
 
75
  except Exception as e:
76
  return f"Error reading file: {str(e)}"
77
 
78
+ def analyze_transcript(file, age, gender, slp_notes):
79
  """Simple CASL analysis"""
80
  if file is None:
81
  return "Please upload a transcript file first."
 
85
  if transcript.startswith("Error") or transcript.startswith("Please"):
86
  return transcript
87
 
88
+ # Add SLP notes to the prompt if provided
89
+ notes_section = ""
90
+ if slp_notes and slp_notes.strip():
91
+ notes_section = f"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
+ SLP CLINICAL NOTES:
94
+ {slp_notes.strip()}
95
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
+ # Simple analysis prompt
98
+ prompt = f"""
99
+ You are a speech-language pathologist analyzing a transcript for CASL assessment.
 
 
100
 
101
+ Patient: {age}-year-old {gender}
 
102
 
103
+ TRANSCRIPT:
104
+ {transcript}{notes_section}
105
 
106
  Please provide a CASL analysis including:
107
 
 
113
 
114
  2. CASL SKILLS ASSESSMENT:
115
  - Lexical/Semantic Skills (Standard Score, Percentile, Level)
116
+ - Syntactic Skills (Standard Score, Percentile, Level)
117
+ - Supralinguistic Skills (Standard Score, Percentile, Level)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
+ 3. TREATMENT RECOMMENDATIONS:
120
+ - List 3-5 specific intervention strategies
121
 
122
+ 4. CLINICAL SUMMARY:
123
+ - Brief explanation of findings and prognosis
124
 
125
+ Use exact quotes from the transcript as evidence.
126
+ Provide realistic standard scores (70-130 range, mean=100).
127
+ {f"Consider the SLP clinical notes in your analysis." if slp_notes and slp_notes.strip() else ""}
128
+ """
 
 
 
 
 
 
 
 
 
 
 
 
129
 
 
 
130
  # Get analysis from Claude API
131
  result = call_claude_api(prompt)
132
  return result
 
159
  value="male"
160
  )
161
 
162
+ slp_notes = gr.Textbox(
163
+ label="SLP Clinical Notes (Optional)",
164
+ placeholder="Enter any additional clinical observations, context, or notes...",
165
+ lines=3
166
+ )
167
+
168
  analyze_btn = gr.Button(
169
  "🔍 Analyze Transcript",
170
  variant="primary"
 
183
  # Connect the analyze button
184
  analyze_btn.click(
185
  analyze_transcript,
186
+ inputs=[file_upload, age, gender, slp_notes],
187
  outputs=[output]
188
  )
189