srijaydeshpande commited on
Commit
e052571
·
1 Parent(s): 904e33b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -77,8 +77,8 @@ def txt_to_html(text):
77
  return html_content
78
 
79
 
80
- def deidentify_doc(pdftext, prompt, maxtokens, temperature, top_probability):
81
- # prompt = "Perform the following actions on given text: 1. Replace any person names with term [redacted] 2. Replace any person addresses with term [redacted]"
82
  # print('Prompt is ',prompt)
83
  # print('-------------------------------------------')
84
  output = model.create_chat_completion(
@@ -98,19 +98,19 @@ def deidentify_doc(pdftext, prompt, maxtokens, temperature, top_probability):
98
  # print(output)
99
  # print('-------------------------------------------------------')
100
 
101
- # prompt = "Perform the following actions on given text: 1. Replace NHS number and Case note number and Date of Birth with term [redacted] 2. Replace only the CALENDAR DATES of format 'day/month/year' with term [redacted] 3. DO NOT REPLACE ANY MEDICAL MEASUREMENTS"
102
- # output = model.create_chat_completion(
103
- # messages=[
104
- # {"role": "assistant", "content": prompt},
105
- # {
106
- # "role": "user",
107
- # "content": output
108
- # }
109
- # ],
110
- # max_tokens=maxtokens,
111
- # temperature=temperature
112
- # )
113
- # output = output['choices'][0]['message']['content']
114
 
115
  # print(prompt)
116
  # print(output)
@@ -119,18 +119,18 @@ def deidentify_doc(pdftext, prompt, maxtokens, temperature, top_probability):
119
  return output
120
 
121
  @spaces.GPU(duration=120)
122
- def pdf_to_text(files, prompt, maxtokens=2048, temperature=0, top_probability=0.95):
123
  files=[files]#remove later
124
  for file in files:
125
- # file_name = os.path.basename(file)
126
- # file_name_splt = file_name.split('.')
127
  # print('File name is ', file_name)
128
- # if (len(file_name_splt) > 1 and file_name_splt[1] == 'pdf'):
129
- # page2content = process_document(file, page_ids=[0])
130
- # pdftext = page2content[1]
131
- pdftext = file # remove later
132
- if (pdftext): #shift this if block to right later
133
- anonymized_text = deidentify_doc(pdftext, prompt, maxtokens, temperature, top_probability)
134
  return anonymized_text
135
 
136
 
@@ -148,7 +148,7 @@ output_text = gr.Textbox()
148
  output_path_component = gr.File(label="Select Output Path")
149
  iface = gr.Interface(
150
  fn=pdf_to_text,
151
- inputs=['textbox', 'textbox'],
152
  # inputs=["textbox", input_folder_text, "textbox", max_tokens, temp_slider, prob_slider],
153
  outputs=output_text,
154
  title='COBIx Endoscopy Report De-Identification',
 
77
  return html_content
78
 
79
 
80
+ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
81
+ 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]"
82
  # print('Prompt is ',prompt)
83
  # print('-------------------------------------------')
84
  output = model.create_chat_completion(
 
98
  # print(output)
99
  # print('-------------------------------------------------------')
100
 
101
+ 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]"
102
+ output = model.create_chat_completion(
103
+ messages=[
104
+ {"role": "assistant", "content": prompt},
105
+ {
106
+ "role": "user",
107
+ "content": output
108
+ }
109
+ ],
110
+ max_tokens=maxtokens,
111
+ temperature=temperature
112
+ )
113
+ output = output['choices'][0]['message']['content']
114
 
115
  # print(prompt)
116
  # print(output)
 
119
  return output
120
 
121
  @spaces.GPU(duration=120)
122
+ def pdf_to_text(files, maxtokens=2048, temperature=0, top_probability=0.95):
123
  files=[files]#remove later
124
  for file in files:
125
+ file_name = os.path.basename(file)
126
+ file_name_splt = file_name.split('.')
127
  # print('File name is ', file_name)
128
+ if (len(file_name_splt) > 1 and file_name_splt[1] == 'pdf'):
129
+ page2content = process_document(file, page_ids=[0])
130
+ pdftext = page2content[1]
131
+ # pdftext = file # remove later
132
+ if (pdftext): #shift this if block to right later
133
+ anonymized_text = deidentify_doc(pdftext, maxtokens, temperature, top_probability)
134
  return anonymized_text
135
 
136
 
 
148
  output_path_component = gr.File(label="Select Output Path")
149
  iface = gr.Interface(
150
  fn=pdf_to_text,
151
+ inputs=['file'],
152
  # inputs=["textbox", input_folder_text, "textbox", max_tokens, temp_slider, prob_slider],
153
  outputs=output_text,
154
  title='COBIx Endoscopy Report De-Identification',