srijaydeshpande commited on
Commit
eba18c5
·
1 Parent(s): 5746a4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -4
app.py CHANGED
@@ -81,10 +81,11 @@ def txt_to_html(text):
81
  html_content += "</body></html>"
82
  return html_content
83
 
84
- @spaces.GPU(duration=180)
85
  def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
86
-
87
- prompt = "In the following text replace any person name and any address with term [redacted], replace any Date of Birth and NHS number with term [redacted]. Output the modified text."
 
88
 
89
  llm = Llama(
90
  model_path="models/Meta-Llama-3-8B-Instruct.Q8_0.gguf",
@@ -107,7 +108,8 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
107
  )
108
  output = output['choices'][0]['message']['content']
109
 
110
- prompt = "Perform the following actions on given text: 1. Replace any person age with term [redacted] 2. DO NOT REPLACE ANY MEDICAL MEASUREMENTS 3. Replace only the CALENDAR DATES of format 'day/month/year' with term [redacted]. Output the modified text."
 
111
 
112
  output = llm.create_chat_completion(
113
  messages=[
@@ -122,6 +124,39 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
122
  )
123
  output = output['choices'][0]['message']['content']
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  return output
126
 
127
  def pdf_to_text(files, maxtokens=2048, temperature=0, top_probability=0.95):
 
81
  html_content += "</body></html>"
82
  return html_content
83
 
84
+ @spaces.GPU(duration=120)
85
  def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
86
+
87
+ #### Remove Names ###
88
+ prompt = "In the following text replace any person name or initials, patients’ names, doctors’ names, the names Dr. with term [redacted]."
89
 
90
  llm = Llama(
91
  model_path="models/Meta-Llama-3-8B-Instruct.Q8_0.gguf",
 
108
  )
109
  output = output['choices'][0]['message']['content']
110
 
111
+ #### Remove Dates ###
112
+ prompt = "In the following text replace any date such as 23/05/22 with term [redacted]."
113
 
114
  output = llm.create_chat_completion(
115
  messages=[
 
124
  )
125
  output = output['choices'][0]['message']['content']
126
 
127
+ #### Remove Locations and Addresses ###
128
+ prompt = "In the following text replace location or address, such as '3970 Longview Drive, CV36HE' with term [redacted]. Replace any GP address with term [redacted]."
129
+
130
+ output = llm.create_chat_completion(
131
+ messages=[
132
+ {"role": "assistant", "content": prompt},
133
+ {
134
+ "role": "user",
135
+ "content": output
136
+ }
137
+ ],
138
+ max_tokens=maxtokens,
139
+ temperature=temperature
140
+ )
141
+ output = output['choices'][0]['message']['content']
142
+
143
+ ### Remove Registration Numbers ###
144
+
145
+ prompt = "In the following text replace 'NHS Number' and 'Case note no.' and any registration number with term [redacted]."
146
+
147
+ output = llm.create_chat_completion(
148
+ messages=[
149
+ {"role": "assistant", "content": prompt},
150
+ {
151
+ "role": "user",
152
+ "content": output
153
+ }
154
+ ],
155
+ max_tokens=maxtokens,
156
+ temperature=temperature
157
+ )
158
+ output = output['choices'][0]['message']['content']
159
+
160
  return output
161
 
162
  def pdf_to_text(files, maxtokens=2048, temperature=0, top_probability=0.95):