Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,13 +68,12 @@ class EmbeddingModel:
|
|
| 68 |
|
| 69 |
@spaces.GPU
|
| 70 |
def compute_similarity(self, sentence1, sentence2, extra_sentence1, extra_sentence2):
|
| 71 |
-
|
| 72 |
sentences = [sentence1, sentence2, extra_sentence1, extra_sentence2]
|
| 73 |
encoded_input = self.tokenizer(sentences, padding=True, truncation=True, return_tensors='pt').to(device)
|
| 74 |
with torch.no_grad():
|
| 75 |
model_output = self.model(**encoded_input)
|
| 76 |
|
| 77 |
-
# Compute embeddings
|
| 78 |
embeddings = last_token_pool(model_output.last_hidden_state, encoded_input['attention_mask'])
|
| 79 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
| 80 |
|
|
@@ -88,9 +87,10 @@ def app_interface():
|
|
| 88 |
with gr.Blocks() as demo:
|
| 89 |
gr.Markdown(title)
|
| 90 |
gr.Markdown(description)
|
|
|
|
|
|
|
| 91 |
|
| 92 |
with gr.Tab("Embedding Generation"):
|
| 93 |
-
task_dropdown = gr.Dropdown(list(tasks.keys()), label="Select a Task", value=list(tasks.keys())[0])
|
| 94 |
input_text_box = gr.Textbox(label="📖Input Text")
|
| 95 |
system_prompt_box = gr.Textbox(label="🤖System Prompt (Optional)")
|
| 96 |
compute_button = gr.Button("Try🐣🛌🏻e5")
|
|
@@ -104,8 +104,8 @@ def app_interface():
|
|
| 104 |
with gr.Tab("Sentence Similarity"):
|
| 105 |
sentence1_box = gr.Textbox(label="Sentence 1")
|
| 106 |
sentence2_box = gr.Textbox(label="Sentence 2")
|
| 107 |
-
extra_sentence1_box = gr.Textbox(label="
|
| 108 |
-
extra_sentence2_box = gr.Textbox(label="
|
| 109 |
similarity_button = gr.Button("Compute Similarity")
|
| 110 |
similarity_output = gr.Label(label="🐣e5-mistral🛌🏻 Similarity Scores")
|
| 111 |
similarity_button.click(
|
|
|
|
| 68 |
|
| 69 |
@spaces.GPU
|
| 70 |
def compute_similarity(self, sentence1, sentence2, extra_sentence1, extra_sentence2):
|
| 71 |
+
|
| 72 |
sentences = [sentence1, sentence2, extra_sentence1, extra_sentence2]
|
| 73 |
encoded_input = self.tokenizer(sentences, padding=True, truncation=True, return_tensors='pt').to(device)
|
| 74 |
with torch.no_grad():
|
| 75 |
model_output = self.model(**encoded_input)
|
| 76 |
|
|
|
|
| 77 |
embeddings = last_token_pool(model_output.last_hidden_state, encoded_input['attention_mask'])
|
| 78 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
| 79 |
|
|
|
|
| 87 |
with gr.Blocks() as demo:
|
| 88 |
gr.Markdown(title)
|
| 89 |
gr.Markdown(description)
|
| 90 |
+
with gr.Row():
|
| 91 |
+
task_dropdown = gr.Dropdown(list(tasks.keys()), label="Select a Task", value=list(tasks.keys())[0])
|
| 92 |
|
| 93 |
with gr.Tab("Embedding Generation"):
|
|
|
|
| 94 |
input_text_box = gr.Textbox(label="📖Input Text")
|
| 95 |
system_prompt_box = gr.Textbox(label="🤖System Prompt (Optional)")
|
| 96 |
compute_button = gr.Button("Try🐣🛌🏻e5")
|
|
|
|
| 104 |
with gr.Tab("Sentence Similarity"):
|
| 105 |
sentence1_box = gr.Textbox(label="Sentence 1")
|
| 106 |
sentence2_box = gr.Textbox(label="Sentence 2")
|
| 107 |
+
extra_sentence1_box = gr.Textbox(label="Sentence 3")
|
| 108 |
+
extra_sentence2_box = gr.Textbox(label="Sentence 4")
|
| 109 |
similarity_button = gr.Button("Compute Similarity")
|
| 110 |
similarity_output = gr.Label(label="🐣e5-mistral🛌🏻 Similarity Scores")
|
| 111 |
similarity_button.click(
|