yilunzhao commited on
Commit
bf2f5f2
1 Parent(s): 03e0db5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -19,14 +19,14 @@ else:
19
  @spaces.GPU
20
  def generate_response(passage: str, question: str) -> str:
21
  # Prepare the input text by combining the passage and question
22
- chat = [{"role": "user", "content": f"Passage: {passage}\nQuestion: {question}"}]
 
23
 
24
- prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
25
- inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
26
- response = model.generate(input_ids=inputs.to(model.device), max_new_tokens=100)
27
-
28
- response = tokenizer.batch_decode(response, skip_special_tokens=True)[0].split("<|assistant|>")[-1].strip()
29
 
 
 
 
30
 
31
  return response
32
 
 
19
  @spaces.GPU
20
  def generate_response(passage: str, question: str) -> str:
21
  # Prepare the input text by combining the passage and question
22
+ message = [f"Passage: {passage}\nQuestion: {question}"]
23
+ inputs = tokenizer(message, return_tensors='pt', return_token_type_ids=False).to('cuda')
24
 
25
+ response = model.generate(**inputs, max_new_tokens=100)
 
 
 
 
26
 
27
+ response = tokenizer.batch_decode(response, skip_special_tokens=True)[0]
28
+
29
+ response = response[len(message[0]):].strip().split('\n')[0]
30
 
31
  return response
32