jason-moore commited on
Commit
3eff2f8
·
1 Parent(s): c3da6a7

improve prompt

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import torch
3
- from transformers import AutoModelForCausalLM, AutoTokenizer
4
  from transformers.utils import logging
5
 
6
  logging.set_verbosity_debug()
@@ -18,6 +18,7 @@ def load_model():
18
  model = AutoModelForCausalLM.from_pretrained(
19
  "omi-health/sum-small",
20
  trust_remote_code=False,
 
21
  device_map="auto" # Let the library decide best device mapping
22
  )
23
  print(f"GPU: {torch.cuda.get_device_name(0)}")
@@ -40,7 +41,7 @@ def generate_soap_note(doctor_patient_conversation):
40
 
41
  try:
42
  # Create a properly formatted prompt with instructions
43
- prompt = f"""<|user|>
44
  Please generate a structured SOAP (Subjective, Objective, Assessment, Plan) note based on the following doctor-patient conversation:
45
 
46
  Include all relevant details in the SOAP note, and ensure that the note is clear and concise. Address each of the following:
@@ -49,8 +50,9 @@ Objective: Observations and findings from the doctor's examination.
49
  Assessment: Doctor's assessment of the patient's condition.
50
  Plan: Recommended next steps for the patient's care.
51
 
52
- Do not include any additional information or context outside of the SOAP note. Do not include the original prompt or conversation in the output.
53
- {doctor_patient_conversation}
 
54
  <|assistant|>"""
55
 
56
  # Tokenize with reasonable max length
@@ -78,10 +80,8 @@ Do not include any additional information or context outside of the SOAP note. D
78
 
79
  # Decode and extract the response part
80
  decoded_response = tokenizer.batch_decode(generate_ids, skip_special_tokens=True)[0]
81
-
82
- # Extract only the assistant's response
83
- if "<|assistant|>" in decoded_response:
84
- decoded_response = decoded_response.split("<|assistant|>")[1].strip()
85
 
86
  return decoded_response
87
 
 
1
  import gradio as gr
2
  import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
4
  from transformers.utils import logging
5
 
6
  logging.set_verbosity_debug()
 
18
  model = AutoModelForCausalLM.from_pretrained(
19
  "omi-health/sum-small",
20
  trust_remote_code=False,
21
+
22
  device_map="auto" # Let the library decide best device mapping
23
  )
24
  print(f"GPU: {torch.cuda.get_device_name(0)}")
 
41
 
42
  try:
43
  # Create a properly formatted prompt with instructions
44
+ prompt = f"""<|system|>
45
  Please generate a structured SOAP (Subjective, Objective, Assessment, Plan) note based on the following doctor-patient conversation:
46
 
47
  Include all relevant details in the SOAP note, and ensure that the note is clear and concise. Address each of the following:
 
50
  Assessment: Doctor's assessment of the patient's condition.
51
  Plan: Recommended next steps for the patient's care.
52
 
53
+ Do not include any additional information or context outside of the SOAP note. Do not include the original prompt or conversation in the output.<|end|>
54
+ <|user|>
55
+ {doctor_patient_conversation}<|end|>
56
  <|assistant|>"""
57
 
58
  # Tokenize with reasonable max length
 
80
 
81
  # Decode and extract the response part
82
  decoded_response = tokenizer.batch_decode(generate_ids, skip_special_tokens=True)[0]
83
+
84
+ logger.debug(decoded_response)
 
 
85
 
86
  return decoded_response
87