srijaydeshpande commited on
Commit
c6fe983
·
1 Parent(s): fae1c05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -42
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
- # chat_template = MessagesFormatterType.LLAMA_3
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
- # provider = LlamaCppPythonProvider(llm)
119
 
120
- # agent = LlamaCppAgent(
121
- # provider,
122
- # system_prompt="You are a helpful assistant.",
123
- # predefined_messages_formatter_type=chat_template,
124
- # debug_output=True
125
- # )
126
 
127
- # settings = provider.get_provider_default_settings()
128
- # settings.temperature = 0.7
129
- # settings.top_k = 40
130
- # settings.top_p = 0.95
131
- # settings.max_tokens = 2048
132
- # settings.repeat_penalty = 1.1
133
- # settings.stream = True
134
-
135
- # messages = BasicChatHistory()
136
-
137
- # stream = agent.get_chat_response(
138
- # prompt + ' : ' + pdftext,
139
- # llm_sampling_settings=settings,
140
- # chat_history=messages,
141
- # returns_streaming_generator=True,
142
- # print_output=False
143
- # )
144
 
145
- # outputs = ""
146
- # for output in stream:
147
- # outputs += output
148
 
149
- # return outputs
150
-
151
- output = llm.create_chat_completion(
152
- messages=[
153
- {"role": "assistant", "content": prompt},
154
- {
155
- "role": "user",
156
- "content": pdftext
157
- }
158
- ],
159
- max_tokens=maxtokens,
160
- temperature=temperature
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(