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)