Tonic commited on
Commit
200153d
1 Parent(s): b85ac58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -50,16 +50,17 @@ def last_token_pool(last_hidden_states: Tensor, attention_mask: Tensor) -> Tenso
50
 
51
  @spaces.GPU
52
  def compute_embeddings(selected_task, input_text, system_prompt):
53
- max_length = 2042 # Define max_length here
54
-
55
  if selected_task == "None":
56
- # Use the system prompt if 'None' is selected
57
- processed_texts = [f'Instruct: {system_prompt}\nQuery: {input_text}']
 
 
58
  else:
59
- # Use the task description from the tasks dictionary
60
  task_description = tasks[selected_task]
61
  processed_texts = [f'Instruct: {task_description}\nQuery: {input_text}']
62
 
 
63
  batch_dict = tokenizer(processed_texts, max_length=max_length - 1, return_attention_mask=False, padding=False, truncation=True)
64
  batch_dict['input_ids'] = [input_ids + [tokenizer.eos_token_id] for input_ids in batch_dict['input_ids']]
65
  batch_dict = tokenizer.pad(batch_dict, padding=True, return_attention_mask=True, return_tensors='pt')
 
50
 
51
  @spaces.GPU
52
  def compute_embeddings(selected_task, input_text, system_prompt):
53
+ max_length = 2042
 
54
  if selected_task == "None":
55
+ if system_prompt:
56
+ processed_texts = [f'Instruct: {system_prompt}\nQuery: {input_text}']
57
+ else:
58
+ processed_texts = [f'Query: {input_text}']
59
  else:
 
60
  task_description = tasks[selected_task]
61
  processed_texts = [f'Instruct: {task_description}\nQuery: {input_text}']
62
 
63
+
64
  batch_dict = tokenizer(processed_texts, max_length=max_length - 1, return_attention_mask=False, padding=False, truncation=True)
65
  batch_dict['input_ids'] = [input_ids + [tokenizer.eos_token_id] for input_ids in batch_dict['input_ids']]
66
  batch_dict = tokenizer.pad(batch_dict, padding=True, return_attention_mask=True, return_tensors='pt')