Spaces:
Running
on
Zero
Running
on
Zero
srijaydeshpande
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import re
|
|
5 |
import gradio as gr
|
6 |
from llama_cpp import Llama
|
7 |
import os
|
|
|
8 |
|
9 |
def process_document(pdf_path, page_ids=None):
|
10 |
|
@@ -63,25 +64,28 @@ def txt_to_html(text):
|
|
63 |
|
64 |
def deidentify_doc(pdftext=""):
|
65 |
|
66 |
-
# prompt = "Please anonymize the following clinical note. Replace all the following information with the term '[redacted]': Redact any strings that might be a name or acronym or initials, patients’ names, doctors’ names, the names of the M.D. or Dr., redact any medical staff names, redact any strings that might be a location or address, such as '3970 Longview Drive', redact any strings that look like 'something years old' or 'age 37', redact any dates and IDs and record dates, redact professions such as 'manager', redact any contact information."
|
67 |
prompt = "Please anonymize the following clinical note. Replace all the following information with the term '[redacted]': Redact any strings that might be a name or initials, patients’ names, doctors’ names, the names Dr., redact any medical staff names, redact any strings that might be a location or address, such as '3970 Longview Drive', redact any strings that look like 'age 37', redact any dates and registration numbers, redact professions such as 'manager', redact any contact information."
|
68 |
|
69 |
-
print('Input prompt is ',prompt)
|
70 |
-
print('Input pdf text is ',pdftext)
|
71 |
-
|
72 |
-
output = model.create_chat_completion(
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
output = output['choices'][0]['message']['content']
|
84 |
-
|
|
|
|
|
|
|
|
|
85 |
return output
|
86 |
|
87 |
def pdf_to_text(file):
|
@@ -95,8 +99,11 @@ def pdf_to_text(file):
|
|
95 |
file.write(html)
|
96 |
return html
|
97 |
|
98 |
-
model_id = "Meta-Llama-3-8B-Instruct.Q5_K_M.gguf"
|
99 |
-
model = Llama(model_path=model_id, n_ctx=2048, n_threads=8, n_gpu_layers=20, n_batch=128)
|
|
|
|
|
|
|
100 |
|
101 |
css = ".gradio-container {background: 'logo.png'}"
|
102 |
|
|
|
5 |
import gradio as gr
|
6 |
from llama_cpp import Llama
|
7 |
import os
|
8 |
+
from gpt4all import GPT4All
|
9 |
|
10 |
def process_document(pdf_path, page_ids=None):
|
11 |
|
|
|
64 |
|
65 |
def deidentify_doc(pdftext=""):
|
66 |
|
|
|
67 |
prompt = "Please anonymize the following clinical note. Replace all the following information with the term '[redacted]': Redact any strings that might be a name or initials, patients’ names, doctors’ names, the names Dr., redact any medical staff names, redact any strings that might be a location or address, such as '3970 Longview Drive', redact any strings that look like 'age 37', redact any dates and registration numbers, redact professions such as 'manager', redact any contact information."
|
68 |
|
69 |
+
# print('Input prompt is ',prompt)
|
70 |
+
# print('Input pdf text is ',pdftext)
|
71 |
+
|
72 |
+
# output = model.create_chat_completion(
|
73 |
+
# messages = [
|
74 |
+
# {"role": "assistant", "content": prompt},
|
75 |
+
# {
|
76 |
+
# "role": "user",
|
77 |
+
# "content": pdftext
|
78 |
+
# }
|
79 |
+
# ],
|
80 |
+
# max_tokens=600,
|
81 |
+
# temperature=0
|
82 |
+
# )
|
83 |
+
# output = output['choices'][0]['message']['content']
|
84 |
+
|
85 |
+
if (pdftext):
|
86 |
+
prompt = prompt + ': ' + pdftext
|
87 |
+
output = model.generate(prompt=prompt, max_tokens=1024, n_batch=128)
|
88 |
+
|
89 |
return output
|
90 |
|
91 |
def pdf_to_text(file):
|
|
|
99 |
file.write(html)
|
100 |
return html
|
101 |
|
102 |
+
# model_id = "Meta-Llama-3-8B-Instruct.Q5_K_M.gguf"
|
103 |
+
# model = Llama(model_path=model_id, n_ctx=2048, n_threads=8, n_gpu_layers=20, n_batch=128)
|
104 |
+
|
105 |
+
model = GPT4All("Meta-Llama-3-8B-Instruct.Q4_0.gguf", n_threads=8, device='gpu')
|
106 |
+
model.chat_session()
|
107 |
|
108 |
css = ".gradio-container {background: 'logo.png'}"
|
109 |
|