Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
-
import accelerate
|
4 |
|
5 |
# Load the model and tokenizer
|
6 |
@st.cache_resource
|
7 |
def load_model_and_tokenizer():
|
8 |
model_name_or_path = "anthropic/mistral-7b"
|
9 |
-
|
10 |
-
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, device_map=accelerator.device_map)
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
12 |
return model, tokenizer
|
13 |
|
@@ -19,8 +17,7 @@ def generate_response(prompt):
|
|
19 |
<|assistant|>:
|
20 |
'''
|
21 |
input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids
|
22 |
-
|
23 |
-
output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id, max_new_tokens=512)
|
24 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
25 |
return response
|
26 |
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
3 |
|
4 |
# Load the model and tokenizer
|
5 |
@st.cache_resource
|
6 |
def load_model_and_tokenizer():
|
7 |
model_name_or_path = "anthropic/mistral-7b"
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name_or_path)
|
|
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
10 |
return model, tokenizer
|
11 |
|
|
|
17 |
<|assistant|>:
|
18 |
'''
|
19 |
input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids
|
20 |
+
output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id, max_new_tokens=512)
|
|
|
21 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
22 |
return response
|
23 |
|