Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from sentence_transformers import SentenceTransformer, util
|
| 3 |
+
model_id = "sentence-transformers/multi-qa-mpnet-base-dot-v1"
|
| 4 |
+
|
| 5 |
+
model = SentenceTransformer(
|
| 6 |
+
model_id
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
def launch(source_sentence, sentences):
|
| 10 |
+
source = model.encode(source_sentence, convert_to_tensor=True)
|
| 11 |
+
references = model.encode([e.strip() for e in sentences.split(",")], convert_to_tensor=True)
|
| 12 |
+
return util.pytorch_cos_sim(source, references)
|
| 13 |
+
|
| 14 |
+
iface = gr.Interface(launch, inputs=["text","text"], outputs="text")
|
| 15 |
+
iface.launch()
|