willwade commited on
Commit
daa76db
·
1 Parent(s): 759b2cf

Enhance model response generation to support conversation initiation

Browse files
Files changed (2) hide show
  1. app.py +7 -5
  2. utils.py +66 -7
app.py CHANGED
@@ -364,7 +364,7 @@ with gr.Blocks(title="Will's AAC Communication Aid") as demo:
364
  topic_dropdown = gr.Dropdown(
365
  choices=[], # Will be populated when a person is selected
366
  label="Topic (optional):",
367
- info="Select a topic relevant to this person",
368
  allow_custom_value=True,
369
  )
370
 
@@ -374,7 +374,7 @@ with gr.Blocks(title="Will's AAC Communication Aid") as demo:
374
  # User input section
375
  with gr.Row():
376
  user_input = gr.Textbox(
377
- label="What they said to me:",
378
  placeholder='Examples:\n"How was your physio session today?"\n"The kids are asking if you want to watch a movie tonight"\n"I\'ve been looking at that new AAC software you mentioned"',
379
  lines=3,
380
  )
@@ -391,14 +391,14 @@ with gr.Blocks(title="Will's AAC Communication Aid") as demo:
391
  # Suggestion type selection
392
  suggestion_type = gr.Radio(
393
  choices=[
394
- "auto_detect",
395
  "model",
 
396
  "common_phrases",
397
  ]
398
  + get_suggestion_categories(),
399
  value="model", # Default to model for better results
400
  label="How should I respond?",
401
- info="Choose what kind of responses you want (model = AI-generated)",
402
  )
403
 
404
  # Model selection
@@ -420,7 +420,9 @@ with gr.Blocks(title="Will's AAC Communication Aid") as demo:
420
  )
421
 
422
  # Generate button
423
- generate_btn = gr.Button("Generate My Responses", variant="primary")
 
 
424
 
425
  # Model status
426
  model_status = gr.Markdown(
 
364
  topic_dropdown = gr.Dropdown(
365
  choices=[], # Will be populated when a person is selected
366
  label="Topic (optional):",
367
+ info="Select a topic to discuss or respond about",
368
  allow_custom_value=True,
369
  )
370
 
 
374
  # User input section
375
  with gr.Row():
376
  user_input = gr.Textbox(
377
+ label="What they said to me: (leave empty to start a conversation)",
378
  placeholder='Examples:\n"How was your physio session today?"\n"The kids are asking if you want to watch a movie tonight"\n"I\'ve been looking at that new AAC software you mentioned"',
379
  lines=3,
380
  )
 
391
  # Suggestion type selection
392
  suggestion_type = gr.Radio(
393
  choices=[
 
394
  "model",
395
+ "auto_detect",
396
  "common_phrases",
397
  ]
398
  + get_suggestion_categories(),
399
  value="model", # Default to model for better results
400
  label="How should I respond?",
401
+ info="Choose response type (model = AI-generated, auto_detect = automatic category detection)",
402
  )
403
 
404
  # Model selection
 
420
  )
421
 
422
  # Generate button
423
+ generate_btn = gr.Button(
424
+ "Generate My Responses/Conversation Starters", variant="primary"
425
+ )
426
 
427
  # Model status
428
  model_status = gr.Markdown(
utils.py CHANGED
@@ -372,13 +372,52 @@ We communicate {frequency}.
372
  elif selected_topic == "cycling" and "cycling" in context:
373
  prompt += "I miss being able to cycle but enjoy talking about past cycling adventures.\n"
374
 
375
- # Add the user's message if provided
376
  if user_input:
 
377
  prompt += f'\n{name} just said to me: "{user_input}"\n'
378
- elif common_phrases:
379
- # Use a common phrase from the person if no message is provided
380
- default_message = common_phrases[0]
381
- prompt += f'\n{name} typically says things like: "{default_message}"\n'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
 
383
  # Add the response prompt with specific guidance
384
  # Check if this is an instruction-tuned model
@@ -389,19 +428,39 @@ We communicate {frequency}.
389
 
390
  if is_instruction_model:
391
  # Use instruction format for instruction-tuned models
392
- prompt += f"""
 
 
393
  <instruction>
394
  Respond to {name} in a way that is natural, brief (1-2 sentences), and directly relevant to what they just said.
395
  Use language appropriate for our relationship.
396
  </instruction>
397
 
398
  My response to {name}:"""
 
 
 
 
 
 
 
 
 
 
399
  else:
400
  # Use standard format for non-instruction models
401
- prompt += f"""
 
 
402
  I want to respond to {name} in a way that is natural, brief (1-2 sentences), and directly relevant to what they just said. I'll use language appropriate for our relationship.
403
 
404
  My response to {name}:"""
 
 
 
 
 
 
405
 
406
  # Generate suggestion
407
  try:
 
372
  elif selected_topic == "cycling" and "cycling" in context:
373
  prompt += "I miss being able to cycle but enjoy talking about past cycling adventures.\n"
374
 
375
+ # Add the user's message if provided, or set up for conversation initiation
376
  if user_input:
377
+ # If user input is provided, we're responding to something
378
  prompt += f'\n{name} just said to me: "{user_input}"\n'
379
+ prompt += f"I want to respond directly to what {name} just said.\n"
380
+ else:
381
+ # No user input means we're initiating a conversation
382
+ if selected_topic:
383
+ # If a topic is selected, initiate conversation about that topic
384
+ prompt += f"\nI'm about to start a conversation with {name} about {selected_topic}.\n"
385
+
386
+ # Add specific context about initiating this topic with this person
387
+ if selected_topic == "football" and "Manchester United" in context:
388
+ prompt += (
389
+ "We both support Manchester United and often discuss matches.\n"
390
+ )
391
+ elif selected_topic == "family" and role in [
392
+ "wife",
393
+ "husband",
394
+ "son",
395
+ "daughter",
396
+ ]:
397
+ prompt += (
398
+ "I want to check in about our family plans or activities.\n"
399
+ )
400
+ elif selected_topic == "health" and role in [
401
+ "doctor",
402
+ "nurse",
403
+ "therapist",
404
+ ]:
405
+ prompt += "I want to discuss my health condition or symptoms.\n"
406
+ elif selected_topic == "work" and role in ["work colleague", "boss"]:
407
+ prompt += "I want to discuss a work-related matter.\n"
408
+
409
+ prompt += f"I want to initiate a conversation about {selected_topic} in a natural way.\n"
410
+ elif common_phrases:
411
+ # Use context about our typical conversations if no specific topic
412
+ prompt += f"\nI'm about to start a conversation with {name}.\n"
413
+ default_message = common_phrases[0]
414
+ prompt += f'{name} typically says things like: "{default_message}"\n'
415
+ prompt += f"We typically talk about: {', '.join(topics)}\n"
416
+ prompt += "I want to initiate a conversation in a natural way based on our relationship.\n"
417
+ else:
418
+ # Generic conversation starter
419
+ prompt += f"\nI'm about to start a conversation with {name}.\n"
420
+ prompt += "I want to initiate a conversation in a natural way based on our relationship.\n"
421
 
422
  # Add the response prompt with specific guidance
423
  # Check if this is an instruction-tuned model
 
428
 
429
  if is_instruction_model:
430
  # Use instruction format for instruction-tuned models
431
+ if user_input:
432
+ # Responding to something
433
+ prompt += f"""
434
  <instruction>
435
  Respond to {name} in a way that is natural, brief (1-2 sentences), and directly relevant to what they just said.
436
  Use language appropriate for our relationship.
437
  </instruction>
438
 
439
  My response to {name}:"""
440
+ else:
441
+ # Initiating a conversation
442
+ prompt += f"""
443
+ <instruction>
444
+ Start a conversation with {name} in a natural, brief (1-2 sentences) way.
445
+ Use language appropriate for our relationship.
446
+ If a topic was selected, focus on that topic.
447
+ </instruction>
448
+
449
+ My conversation starter to {name}:"""
450
  else:
451
  # Use standard format for non-instruction models
452
+ if user_input:
453
+ # Responding to something
454
+ prompt += f"""
455
  I want to respond to {name} in a way that is natural, brief (1-2 sentences), and directly relevant to what they just said. I'll use language appropriate for our relationship.
456
 
457
  My response to {name}:"""
458
+ else:
459
+ # Initiating a conversation
460
+ prompt += f"""
461
+ I want to start a conversation with {name} in a natural, brief (1-2 sentences) way. I'll use language appropriate for our relationship.
462
+
463
+ My conversation starter to {name}:"""
464
 
465
  # Generate suggestion
466
  try: