srijaydeshpande commited on
Commit
011bc8b
·
1 Parent(s): f16f96a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -5
app.py CHANGED
@@ -82,9 +82,33 @@ def deidentify_doc(pdftext=""):
82
  # )
83
  # output = output['choices'][0]['message']['content']
84
 
85
- if (pdftext):
86
- prompt = prompt + ': ' + pdftext
87
- output = model.generate(prompt=prompt, max_tokens=1024, n_batch=128)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  return output
90
 
@@ -102,8 +126,16 @@ def pdf_to_text(file):
102
  # model_id = "Meta-Llama-3-8B-Instruct.Q5_K_M.gguf"
103
  # model = Llama(model_path=model_id, n_ctx=2048, n_threads=8, n_gpu_layers=20, n_batch=128)
104
 
105
- model = GPT4All("Meta-Llama-3-8B-Instruct.Q4_0.gguf", n_threads=8, device='gpu')
106
- model.chat_session()
 
 
 
 
 
 
 
 
107
 
108
  css = ".gradio-container {background: 'logo.png'}"
109
 
 
82
  # )
83
  # output = output['choices'][0]['message']['content']
84
 
85
+ # if (pdftext):
86
+ # prompt = prompt + ': ' + pdftext
87
+ # output = model.generate(prompt=prompt, max_tokens=1024, n_batch=128)
88
+
89
+ messages = [
90
+ {"role": "assistant",
91
+ "content": prompt},
92
+ {"role": "user",
93
+ "content": pdftext}, ]
94
+ prompt = pipeline.tokenizer.apply_chat_template(
95
+ messages,
96
+ tokenize=False,
97
+ add_generation_prompt=True
98
+ )
99
+ terminators = [
100
+ pipeline.tokenizer.eos_token_id,
101
+ pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
102
+ ]
103
+ outputs = pipeline(
104
+ prompt,
105
+ max_new_tokens=600,
106
+ eos_token_id=terminators,
107
+ do_sample=True,
108
+ temperature=0.6,
109
+ top_p=0.9,
110
+ )
111
+ output = outputs[0]["generated_text"][len(prompt):]
112
 
113
  return output
114
 
 
126
  # model_id = "Meta-Llama-3-8B-Instruct.Q5_K_M.gguf"
127
  # model = Llama(model_path=model_id, n_ctx=2048, n_threads=8, n_gpu_layers=20, n_batch=128)
128
 
129
+ # model = GPT4All("Meta-Llama-3-8B-Instruct.Q4_0.gguf", n_threads=8, device='gpu')
130
+ # model.chat_session()
131
+
132
+ model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
133
+ model = transformers.pipeline(
134
+ "text-generation",
135
+ model=model_id,
136
+ model_kwargs={"torch_dtype": torch.bfloat16},
137
+ device="cuda",
138
+ )
139
 
140
  css = ".gradio-container {background: 'logo.png'}"
141