Tonic commited on
Commit
97173ba
β€’
1 Parent(s): cf71836

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -52,8 +52,12 @@ class EmbeddingModel:
52
 
53
  @spaces.GPU
54
  def compute_embeddings(self, selected_task, input_text):
 
 
 
 
 
55
  max_length = 2042
56
- task_description = tasks[selected_task]
57
  processed_texts = [f'Instruct: {task_description}\nQuery: {input_text}']
58
 
59
  batch_dict = self.tokenizer(processed_texts, max_length=max_length - 1, return_attention_mask=False, padding=False, truncation=True)
@@ -68,7 +72,11 @@ class EmbeddingModel:
68
 
69
  @spaces.GPU
70
  def compute_similarity(self, selected_task, sentence1, sentence2, extra_sentence1, extra_sentence2):
71
-
 
 
 
 
72
  # Compute embeddings for each sentence
73
  embeddings1 = self.compute_embeddings(self.selected_task, sentence1)
74
  embeddings2 = self.compute_embeddings(self.selected_task, sentence2)
 
52
 
53
  @spaces.GPU
54
  def compute_embeddings(self, selected_task, input_text):
55
+ try:
56
+ task_description = tasks[selected_task]
57
+ except KeyError:
58
+ print(f"Selected task not found: {selected_task}")
59
+ return f"Error: Task '{selected_task}' not found. Please select a valid task."
60
  max_length = 2042
 
61
  processed_texts = [f'Instruct: {task_description}\nQuery: {input_text}']
62
 
63
  batch_dict = self.tokenizer(processed_texts, max_length=max_length - 1, return_attention_mask=False, padding=False, truncation=True)
 
72
 
73
  @spaces.GPU
74
  def compute_similarity(self, selected_task, sentence1, sentence2, extra_sentence1, extra_sentence2):
75
+ try:
76
+ task_description = tasks[selected_task]
77
+ except KeyError:
78
+ print(f"Selected task not found: {selected_task}")
79
+ return f"Error: Task '{selected_task}' not found. Please select a valid task."
80
  # Compute embeddings for each sentence
81
  embeddings1 = self.compute_embeddings(self.selected_task, sentence1)
82
  embeddings2 = self.compute_embeddings(self.selected_task, sentence2)