Commit ·
cd5a3f1
1
Parent(s): e693246
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ from llama_cpp_agent import LlamaCppAgent, MessagesFormatterType
|
|
| 13 |
from llama_cpp_agent.providers import LlamaCppPythonProvider
|
| 14 |
from llama_cpp_agent.chat_history import BasicChatHistory
|
| 15 |
from llama_cpp_agent.chat_history.messages import Roles
|
| 16 |
-
from vllm import LLM, SamplingParams
|
| 17 |
|
| 18 |
# subprocess.run('pip install llama-cpp-python==0.2.75 --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu124', shell=True)
|
| 19 |
# subprocess.run('pip install llama-cpp-agent==0.2.10', shell=True)
|
|
@@ -86,18 +86,6 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
| 86 |
|
| 87 |
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."
|
| 88 |
|
| 89 |
-
# prompt = """
|
| 90 |
-
# Perform the following actions on given report:
|
| 91 |
-
# 1. Replace any person names, age, date of birth, gender with term [redacted]
|
| 92 |
-
# 2. Replace any addresses with term [redacted]
|
| 93 |
-
# 3. DO NOT REPLACE ANY MEDICAL MEASUREMENTS
|
| 94 |
-
# 4. Replace only the CALENDAR DATES of format 'day/month/year' with term [redacted]
|
| 95 |
-
# """
|
| 96 |
-
|
| 97 |
-
# prompt = """
|
| 98 |
-
# Remove person names, any dates, date of birth, age, gender, registration numbers and any addresses from the following report.
|
| 99 |
-
# """
|
| 100 |
-
|
| 101 |
# model = Llama(
|
| 102 |
# model_path=model_id,
|
| 103 |
# flash_attn=True,
|
|
@@ -108,19 +96,11 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
| 108 |
|
| 109 |
# chat_template = MessagesFormatterType.LLAMA_3
|
| 110 |
|
| 111 |
-
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
| 112 |
-
|
| 113 |
-
# llm = Llama(
|
| 114 |
-
# model_path="models/Meta-Llama-3-8B-Instruct.Q8_0.gguf",
|
| 115 |
-
# flash_attn=True,
|
| 116 |
-
# n_gpu_layers=81,
|
| 117 |
-
# n_batch=1024,
|
| 118 |
-
# n_ctx=8192,
|
| 119 |
-
# )
|
| 120 |
|
| 121 |
-
llm = LLM(model="meta-llama/Meta-Llama-3-8B-Instruct")
|
| 122 |
-
outputs = llm.generate([prompt], sampling_params)
|
| 123 |
-
output = outputs[0].outputs[0].text
|
| 124 |
|
| 125 |
# provider = LlamaCppPythonProvider(llm)
|
| 126 |
|
|
@@ -152,37 +132,45 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
| 152 |
# output = ""
|
| 153 |
# for op in stream:
|
| 154 |
# output += op
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
|
| 169 |
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."
|
| 170 |
|
| 171 |
-
outputs = llm.generate([output], sampling_params)
|
| 172 |
-
output = outputs[0].outputs[0].text
|
| 173 |
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
|
| 187 |
# print(prompt)
|
| 188 |
# print(output)
|
|
|
|
| 13 |
from llama_cpp_agent.providers import LlamaCppPythonProvider
|
| 14 |
from llama_cpp_agent.chat_history import BasicChatHistory
|
| 15 |
from llama_cpp_agent.chat_history.messages import Roles
|
| 16 |
+
# from vllm import LLM, SamplingParams
|
| 17 |
|
| 18 |
# subprocess.run('pip install llama-cpp-python==0.2.75 --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu124', shell=True)
|
| 19 |
# subprocess.run('pip install llama-cpp-agent==0.2.10', shell=True)
|
|
|
|
| 86 |
|
| 87 |
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."
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
# model = Llama(
|
| 90 |
# model_path=model_id,
|
| 91 |
# flash_attn=True,
|
|
|
|
| 96 |
|
| 97 |
# chat_template = MessagesFormatterType.LLAMA_3
|
| 98 |
|
| 99 |
+
# sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
+
# llm = LLM(model="meta-llama/Meta-Llama-3-8B-Instruct")
|
| 102 |
+
# outputs = llm.generate([prompt], sampling_params)
|
| 103 |
+
# output = outputs[0].outputs[0].text
|
| 104 |
|
| 105 |
# provider = LlamaCppPythonProvider(llm)
|
| 106 |
|
|
|
|
| 132 |
# output = ""
|
| 133 |
# for op in stream:
|
| 134 |
# output += op
|
| 135 |
+
|
| 136 |
+
llm = Llama(
|
| 137 |
+
model_path="models/Meta-Llama-3-8B-Instruct.Q8_0.gguf",
|
| 138 |
+
flash_attn=True,
|
| 139 |
+
n_gpu_layers=81,
|
| 140 |
+
n_batch=1024,
|
| 141 |
+
n_ctx=8192,
|
| 142 |
+
)
|
| 143 |
|
| 144 |
+
output = llm.create_chat_completion(
|
| 145 |
+
messages=[
|
| 146 |
+
{"role": "assistant", "content": prompt},
|
| 147 |
+
{
|
| 148 |
+
"role": "user",
|
| 149 |
+
"content": pdftext
|
| 150 |
+
}
|
| 151 |
+
],
|
| 152 |
+
max_tokens=maxtokens,
|
| 153 |
+
temperature=temperature
|
| 154 |
+
)
|
| 155 |
+
output = output['choices'][0]['message']['content']
|
| 156 |
|
| 157 |
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."
|
| 158 |
|
| 159 |
+
# outputs = llm.generate([output], sampling_params)
|
| 160 |
+
# output = outputs[0].outputs[0].text
|
| 161 |
|
| 162 |
+
output = llm.create_chat_completion(
|
| 163 |
+
messages=[
|
| 164 |
+
{"role": "assistant", "content": prompt},
|
| 165 |
+
{
|
| 166 |
+
"role": "user",
|
| 167 |
+
"content": output
|
| 168 |
+
}
|
| 169 |
+
],
|
| 170 |
+
max_tokens=maxtokens,
|
| 171 |
+
temperature=temperature
|
| 172 |
+
)
|
| 173 |
+
output = output['choices'][0]['message']['content']
|
| 174 |
|
| 175 |
# print(prompt)
|
| 176 |
# print(output)
|