srijaydeshpande commited on
Commit
a217b34
·
1 Parent(s): 61a98ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -71,8 +71,8 @@ def txt_to_html(text):
71
  return html_content
72
 
73
 
74
- def deidentify_doc(pdftext, prompt, maxtokens, temperature, top_probability):
75
- # prompt = "Perform the following actions on given text: 1. Replace any person names with term [redacted] 2. Replace any person addresses with term [redacted]"
76
  print('Prompt is ',prompt)
77
  print('-------------------------------------------')
78
  output = model.create_chat_completion(
@@ -92,19 +92,19 @@ def deidentify_doc(pdftext, prompt, maxtokens, temperature, top_probability):
92
  # print(output)
93
  # print('-------------------------------------------------------')
94
 
95
- # 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"
96
- # output = model.create_chat_completion(
97
- # messages=[
98
- # {"role": "assistant", "content": prompt},
99
- # {
100
- # "role": "user",
101
- # "content": output
102
- # }
103
- # ],
104
- # max_tokens=maxtokens,
105
- # temperature=temperature
106
- # )
107
- # output = output['choices'][0]['message']['content']
108
 
109
  # print(prompt)
110
  # print(output)
@@ -113,7 +113,7 @@ def deidentify_doc(pdftext, prompt, maxtokens, temperature, top_probability):
113
  return output
114
 
115
  @spaces.GPU(duration=120)
116
- def pdf_to_text(files, output_folder, prompt, maxtokens=2048, temperature=0, top_probability=0.95):
117
  files=[files]#remove later
118
  for file in files:
119
  file_name = os.path.basename(file)
@@ -125,7 +125,7 @@ def pdf_to_text(files, output_folder, prompt, maxtokens=2048, temperature=0, top
125
  pdftext = page2content[1]
126
  # pdftext = file # remove later
127
  if (pdftext): #shift this if block to right later
128
- anonymized_text = deidentify_doc(pdftext, prompt, maxtokens, temperature, top_probability)
129
  return anonymized_text
130
 
131
 
@@ -143,7 +143,7 @@ output_text = gr.Textbox()
143
  output_path_component = gr.File(label="Select Output Path")
144
  iface = gr.Interface(
145
  fn=pdf_to_text,
146
- inputs=['file', input_folder_text, "textbox"],
147
  # inputs=["textbox", input_folder_text, "textbox", max_tokens, temp_slider, prob_slider],
148
  outputs=output_text,
149
  title='COBIx Endoscopy Report De-Identification',
 
71
  return html_content
72
 
73
 
74
+ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
75
+ prompt = "Perform the following actions on given text: 1. Replace any person names with term [redacted] 2. Replace any person addresses with term [redacted]"
76
  print('Prompt is ',prompt)
77
  print('-------------------------------------------')
78
  output = model.create_chat_completion(
 
92
  # print(output)
93
  # print('-------------------------------------------------------')
94
 
95
+ 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"
96
+ output = model.create_chat_completion(
97
+ messages=[
98
+ {"role": "assistant", "content": prompt},
99
+ {
100
+ "role": "user",
101
+ "content": output
102
+ }
103
+ ],
104
+ max_tokens=maxtokens,
105
+ temperature=temperature
106
+ )
107
+ output = output['choices'][0]['message']['content']
108
 
109
  # print(prompt)
110
  # print(output)
 
113
  return output
114
 
115
  @spaces.GPU(duration=120)
116
+ def pdf_to_text(files, output_folder, maxtokens=2048, temperature=0, top_probability=0.95):
117
  files=[files]#remove later
118
  for file in files:
119
  file_name = os.path.basename(file)
 
125
  pdftext = page2content[1]
126
  # pdftext = file # remove later
127
  if (pdftext): #shift this if block to right later
128
+ anonymized_text = deidentify_doc(pdftext, maxtokens, temperature, top_probability)
129
  return anonymized_text
130
 
131
 
 
143
  output_path_component = gr.File(label="Select Output Path")
144
  iface = gr.Interface(
145
  fn=pdf_to_text,
146
+ inputs=['file', input_folder_text],
147
  # inputs=["textbox", input_folder_text, "textbox", max_tokens, temp_slider, prob_slider],
148
  outputs=output_text,
149
  title='COBIx Endoscopy Report De-Identification',