seawolf2357 commited on
Commit
9872f0b
ยท
verified ยท
1 Parent(s): 85b887d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
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=True).input_ids.to(accelerator.device)
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) # ์—ฌ๊ธฐ์—์„œ 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)