srijaydeshpande commited on
Commit
4d9641c
·
1 Parent(s): 1272fbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -40
app.py CHANGED
@@ -83,49 +83,77 @@ def txt_to_html(text):
83
 
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
- # print('Prompt is ',prompt)
87
- # print('-------------------------------------------')
88
-
89
- model_id = "models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf"
90
- # model = Llama(model_path=model_id, n_ctx=2048, n_threads=8, n_gpu_layers=-1, n_batch=128)
91
- model = Llama(
92
- model_path=model_id,
93
- flash_attn=True,
94
- n_gpu_layers=81,
95
- n_batch=1024,
96
- n_ctx=8192,
97
- )
98
-
99
- output = model.create_chat_completion(
100
- messages=[
101
- {"role": "assistant", "content": prompt},
102
- {
103
- "role": "user",
104
- "content": pdftext
105
- }
106
- ],
107
- max_tokens=maxtokens,
108
- temperature=temperature
109
- )
110
- output = output['choices'][0]['message']['content']
111
 
112
- # print(prompt)
113
- # print(output)
114
- # print('-------------------------------------------------------')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
- 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]"
117
- output = model.create_chat_completion(
118
- messages=[
119
- {"role": "assistant", "content": prompt},
120
- {
121
- "role": "user",
122
- "content": output
123
- }
124
- ],
125
- max_tokens=maxtokens,
126
- temperature=temperature
 
 
 
 
 
 
 
127
  )
128
- output = output['choices'][0]['message']['content']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  # print(prompt)
131
  # print(output)
 
83
 
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
+ # model_id = "models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf"
88
+ # # model = Llama(model_path=model_id, n_ctx=2048, n_threads=8, n_gpu_layers=-1, n_batch=128)
89
+ # model = Llama(
90
+ # model_path=model_id,
91
+ # flash_attn=True,
92
+ # n_gpu_layers=81,
93
+ # n_batch=1024,
94
+ # n_ctx=8192,
95
+ # )
96
+
97
+ llm = Llama(
98
+ model_path="models/Meta-Llama-3-70B-Instruct-Q3_K_M.gguf",
99
+ flash_attn=True,
100
+ n_gpu_layers=81,
101
+ n_batch=1024,
102
+ n_ctx=8192,
103
+ )
104
+ provider = LlamaCppPythonProvider(llm)
105
 
106
+ agent = LlamaCppAgent(
107
+ provider,
108
+ )
109
+
110
+ settings = provider.get_provider_default_settings()
111
+ settings.temperature = 0.7
112
+ settings.top_k = 40
113
+ settings.top_p = 0.95
114
+ settings.max_tokens = 2048
115
+ settings.repeat_penalty = 1.1
116
+ settings.stream = True
117
+
118
+ stream = agent.get_chat_response(
119
+ message,
120
+ llm_sampling_settings=settings,
121
+ chat_history=messages,
122
+ returns_streaming_generator=True,
123
+ print_output=False
124
  )
125
+
126
+ outputs = ""
127
+ for output in stream:
128
+ outputs += output
129
+ yield outputs
130
+
131
+ # output = model.create_chat_completion(
132
+ # messages=[
133
+ # {"role": "assistant", "content": prompt},
134
+ # {
135
+ # "role": "user",
136
+ # "content": pdftext
137
+ # }
138
+ # ],
139
+ # max_tokens=maxtokens,
140
+ # temperature=temperature
141
+ # )
142
+ # output = output['choices'][0]['message']['content']
143
+
144
+ # 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]"
145
+ # output = model.create_chat_completion(
146
+ # messages=[
147
+ # {"role": "assistant", "content": prompt},
148
+ # {
149
+ # "role": "user",
150
+ # "content": output
151
+ # }
152
+ # ],
153
+ # max_tokens=maxtokens,
154
+ # temperature=temperature
155
+ # )
156
+ # output = output['choices'][0]['message']['content']
157
 
158
  # print(prompt)
159
  # print(output)