srijaydeshpande commited on
Commit
9974dfc
·
1 Parent(s): 3fa379b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -77,8 +77,8 @@ def txt_to_html(text):
77
  return html_content
78
 
79
 
80
- def deidentify_doc(pdftext, 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, 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,7 +119,7 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
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)
@@ -130,7 +130,7 @@ def pdf_to_text(files, maxtokens=2048, temperature=0, top_probability=0.95):
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,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=['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',
 
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
  # 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
  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)
 
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
  output_path_component = gr.File(label="Select Output Path")
149
  iface = gr.Interface(
150
  fn=pdf_to_text,
151
+ inputs=['file', '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',