Commit ·
4775cda
1
Parent(s): 565d377
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,9 +82,9 @@ 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 |
-
|
| 87 |
-
|
| 88 |
# model_id = "models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf"
|
| 89 |
# # model = Llama(model_path=model_id, n_ctx=2048, n_threads=8, n_gpu_layers=-1, n_batch=128)
|
| 90 |
# model = Llama(
|
|
@@ -96,20 +96,16 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
| 96 |
# )
|
| 97 |
|
| 98 |
chat_template = MessagesFormatterType.LLAMA_3
|
| 99 |
-
|
| 100 |
-
print('Control 1-----------------------------------')
|
| 101 |
|
| 102 |
llm = Llama(
|
| 103 |
model_path="models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf",
|
| 104 |
flash_attn=True,
|
| 105 |
-
n_gpu_layers=
|
| 106 |
n_batch=1024,
|
| 107 |
n_ctx=8192,
|
| 108 |
)
|
| 109 |
-
print('Control 2-----------------------------------')
|
| 110 |
|
| 111 |
provider = LlamaCppPythonProvider(llm)
|
| 112 |
-
print('Control 3-----------------------------------')
|
| 113 |
|
| 114 |
agent = LlamaCppAgent(
|
| 115 |
provider,
|
|
@@ -117,7 +113,6 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
| 117 |
predefined_messages_formatter_type=chat_template,
|
| 118 |
debug_output=True
|
| 119 |
)
|
| 120 |
-
print('Control 4-----------------------------------')
|
| 121 |
|
| 122 |
settings = provider.get_provider_default_settings()
|
| 123 |
settings.temperature = 0.7
|
|
@@ -130,14 +125,13 @@ def deidentify_doc(pdftext, maxtokens, temperature, top_probability):
|
|
| 130 |
messages = BasicChatHistory()
|
| 131 |
|
| 132 |
stream = agent.get_chat_response(
|
| 133 |
-
prompt,
|
| 134 |
llm_sampling_settings=settings,
|
| 135 |
chat_history=messages,
|
| 136 |
returns_streaming_generator=True,
|
| 137 |
print_output=False
|
| 138 |
)
|
| 139 |
-
|
| 140 |
-
print(stream)
|
| 141 |
outputs = ""
|
| 142 |
for output in stream:
|
| 143 |
outputs += output
|
|
|
|
| 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 = "Anonymize the following report"
|
| 87 |
+
|
| 88 |
# model_id = "models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf"
|
| 89 |
# # model = Llama(model_path=model_id, n_ctx=2048, n_threads=8, n_gpu_layers=-1, n_batch=128)
|
| 90 |
# model = Llama(
|
|
|
|
| 96 |
# )
|
| 97 |
|
| 98 |
chat_template = MessagesFormatterType.LLAMA_3
|
|
|
|
|
|
|
| 99 |
|
| 100 |
llm = Llama(
|
| 101 |
model_path="models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf",
|
| 102 |
flash_attn=True,
|
| 103 |
+
n_gpu_layers=-1,
|
| 104 |
n_batch=1024,
|
| 105 |
n_ctx=8192,
|
| 106 |
)
|
|
|
|
| 107 |
|
| 108 |
provider = LlamaCppPythonProvider(llm)
|
|
|
|
| 109 |
|
| 110 |
agent = LlamaCppAgent(
|
| 111 |
provider,
|
|
|
|
| 113 |
predefined_messages_formatter_type=chat_template,
|
| 114 |
debug_output=True
|
| 115 |
)
|
|
|
|
| 116 |
|
| 117 |
settings = provider.get_provider_default_settings()
|
| 118 |
settings.temperature = 0.7
|
|
|
|
| 125 |
messages = BasicChatHistory()
|
| 126 |
|
| 127 |
stream = agent.get_chat_response(
|
| 128 |
+
prompt + ' : ' + pdftext,
|
| 129 |
llm_sampling_settings=settings,
|
| 130 |
chat_history=messages,
|
| 131 |
returns_streaming_generator=True,
|
| 132 |
print_output=False
|
| 133 |
)
|
| 134 |
+
|
|
|
|
| 135 |
outputs = ""
|
| 136 |
for output in stream:
|
| 137 |
outputs += output
|