Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,11 @@ hf_api_key = os.getenv('HF_API_KEY')
|
|
13 |
# λͺ¨λΈ λ° ν ν¬λμ΄μ μ€μ
|
14 |
model_id = "microsoft/phi-2"
|
15 |
tokenizer = AutoTokenizer.from_pretrained(model_id, token=hf_api_key, trust_remote_code=True)
|
|
|
|
|
|
|
|
|
|
|
16 |
model = AutoModelForCausalLM.from_pretrained(
|
17 |
model_id,
|
18 |
token=hf_api_key,
|
@@ -41,7 +46,7 @@ def format_prompt(prompt, retrieved_documents, k):
|
|
41 |
|
42 |
def generate(formatted_prompt):
|
43 |
prompt_text = f"{SYS_PROMPT} {formatted_prompt}"
|
44 |
-
input_ids = tokenizer(prompt_text, return_tensors="pt", padding=
|
45 |
outputs = model.generate(
|
46 |
input_ids,
|
47 |
max_new_tokens=1024,
|
@@ -67,4 +72,4 @@ iface = gr.Interface(
|
|
67 |
description="This chatbot provides more accurate answers by searching relevant documents and generating responses."
|
68 |
)
|
69 |
|
70 |
-
iface.launch(share=True)
|
|
|
13 |
# λͺ¨λΈ λ° ν ν¬λμ΄μ μ€μ
|
14 |
model_id = "microsoft/phi-2"
|
15 |
tokenizer = AutoTokenizer.from_pretrained(model_id, token=hf_api_key, trust_remote_code=True)
|
16 |
+
|
17 |
+
# ν ν¬λμ΄μ μ ν¨λ© ν ν° μ€μ
|
18 |
+
if tokenizer.pad_token is None:
|
19 |
+
tokenizer.pad_token = tokenizer.eos_token # EOS ν ν°μ ν¨λ© ν ν°μΌλ‘ μ¬μ©
|
20 |
+
|
21 |
model = AutoModelForCausalLM.from_pretrained(
|
22 |
model_id,
|
23 |
token=hf_api_key,
|
|
|
46 |
|
47 |
def generate(formatted_prompt):
|
48 |
prompt_text = f"{SYS_PROMPT} {formatted_prompt}"
|
49 |
+
input_ids = tokenizer(prompt_text, return_tensors="pt", padding="max_length", max_length=512).input_ids.to(accelerator.device)
|
50 |
outputs = model.generate(
|
51 |
input_ids,
|
52 |
max_new_tokens=1024,
|
|
|
72 |
description="This chatbot provides more accurate answers by searching relevant documents and generating responses."
|
73 |
)
|
74 |
|
75 |
+
iface.launch(share=True)
|