Commit ·
c6fe983
1
Parent(s): fae1c05
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,6 +82,7 @@ def txt_to_html(text):
|
|
| 82 |
|
| 83 |
@spaces.GPU(duration=120)
|
| 84 |
def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
|
|
| 85 |
# 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]"
|
| 86 |
# prompt = """
|
| 87 |
# Perform the following actions on given report:
|
|
@@ -105,7 +106,7 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
| 105 |
# n_ctx=8192,
|
| 106 |
# )
|
| 107 |
|
| 108 |
-
|
| 109 |
|
| 110 |
llm = Llama(
|
| 111 |
model_path="models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf",
|
|
@@ -115,51 +116,49 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
| 115 |
n_ctx=8192,
|
| 116 |
)
|
| 117 |
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
|
| 149 |
-
#
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
)
|
| 162 |
-
output = output['choices'][0]['message']['content']
|
| 163 |
|
| 164 |
# 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]"
|
| 165 |
# output = model.create_chat_completion(
|
|
|
|
| 82 |
|
| 83 |
@spaces.GPU(duration=120)
|
| 84 |
def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
| 85 |
+
|
| 86 |
# 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]"
|
| 87 |
# prompt = """
|
| 88 |
# Perform the following actions on given report:
|
|
|
|
| 106 |
# n_ctx=8192,
|
| 107 |
# )
|
| 108 |
|
| 109 |
+
chat_template = MessagesFormatterType.LLAMA_3
|
| 110 |
|
| 111 |
llm = Llama(
|
| 112 |
model_path="models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf",
|
|
|
|
| 116 |
n_ctx=8192,
|
| 117 |
)
|
| 118 |
|
| 119 |
+
provider = LlamaCppPythonProvider(llm)
|
| 120 |
|
| 121 |
+
agent = LlamaCppAgent(
|
| 122 |
+
provider,
|
| 123 |
+
system_prompt="You are a helpful assistant.",
|
| 124 |
+
predefined_messages_formatter_type=chat_template,
|
| 125 |
+
debug_output=True
|
| 126 |
+
)
|
| 127 |
|
| 128 |
+
settings = provider.get_provider_default_settings()
|
| 129 |
+
settings.temperature = temperature
|
| 130 |
+
settings.top_k = 40
|
| 131 |
+
settings.top_p = top_probability
|
| 132 |
+
settings.max_tokens = maxtokens
|
| 133 |
+
settings.repeat_penalty = 1.1
|
| 134 |
+
settings.stream = True
|
| 135 |
+
|
| 136 |
+
messages = BasicChatHistory()
|
| 137 |
+
|
| 138 |
+
stream = agent.get_chat_response(
|
| 139 |
+
prompt + ' : ' + pdftext,
|
| 140 |
+
llm_sampling_settings=settings,
|
| 141 |
+
chat_history=messages,
|
| 142 |
+
returns_streaming_generator=True,
|
| 143 |
+
print_output=False
|
| 144 |
+
)
|
| 145 |
|
| 146 |
+
output = ""
|
| 147 |
+
for op in stream:
|
| 148 |
+
output += op
|
| 149 |
|
| 150 |
+
# output = llm.create_chat_completion(
|
| 151 |
+
# messages=[
|
| 152 |
+
# {"role": "assistant", "content": prompt},
|
| 153 |
+
# {
|
| 154 |
+
# "role": "user",
|
| 155 |
+
# "content": pdftext
|
| 156 |
+
# }
|
| 157 |
+
# ],
|
| 158 |
+
# max_tokens=maxtokens,
|
| 159 |
+
# temperature=temperature
|
| 160 |
+
# )
|
| 161 |
+
# output = output['choices'][0]['message']['content']
|
|
|
|
|
|
|
| 162 |
|
| 163 |
# 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]"
|
| 164 |
# output = model.create_chat_completion(
|