Commit ·
eba18c5
1
Parent(s): 5746a4c
Update app.py
Browse files80 unmodified lines8182838485868788899016 unmodified lines1071081091101111121138 unmodified lines12212312412512612780 unmodified lineshtml_content += "</body></html>"return html_content@spaces.GPU(duration=180)def deidentify_doc(pdftext, maxtokens, temperature, top_probability):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."llm = Llama(model_path="models/Meta-Llama-3-8B-Instruct.Q8_0.gguf",16 unmodified lines)output = output['choices'][0]['message']['content']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."output = llm.create_chat_completion(messages=[8 unmodified lines)output = output['choices'][0]['message']['content']return outputdef pdf_to_text(files, maxtokens=2048, temperature=0, top_probability=0.95):80 unmodified lines818283848586878889909116 unmodified lines1081091101111121131141158 unmodified lines12412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116280 unmodified lineshtml_content += "</body></html>"return html_content@spaces.GPU(duration=120)def deidentify_doc(pdftext, maxtokens, temperature, top_probability):#### Remove Names ###prompt = "In the following text replace any person name or initials, patients’ names, doctors’ names, the names Dr. with term [redacted]."llm = Llama(model_path="models/Meta-Llama-3-8B-Instruct.Q8_0.gguf",16 unmodified lines)output = output['choices'][0]['message']['content']#### Remove Dates ###prompt = "In the following text replace any date such as 23/05/22 with term [redacted]."output = llm.create_chat_completion(messages=[8 unmodified lines)output = output['choices'][0]['message']['content']#### Remove Locations and Addresses ###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]."output = llm.create_chat_completion(messages=[{"role": "assistant", "content": prompt},{"role": "user","content": output}],max_tokens=maxtokens,temperature=temperature)output = output['choices'][0]['message']['content']### Remove Registration Numbers ###prompt = "In the following text replace 'NHS Number' and 'Case note no.' and any registration number with term [redacted]."output = llm.create_chat_completion(messages=[{"role": "assistant", "content": prompt},{"role": "user","content": output}],max_tokens=maxtokens,temperature=temperature)output = output['choices'][0]['message']['content']return outputdef pdf_to_text(files, maxtokens=2048, temperature=0, top_probability=0.95):
app.py+39-4