DexterSptizu
commited on
Commit
•
1107e2d
1
Parent(s):
d26f65d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from wordllama import WordLlama
|
3 |
+
|
4 |
+
# Load the default WordLlama model
|
5 |
+
wl = WordLlama.load()
|
6 |
+
|
7 |
+
# Define the function that calculates similarity between two sentences
|
8 |
+
def calculate_similarity(sentence1, sentence2):
|
9 |
+
similarity_score = wl.similarity(sentence1, sentence2)
|
10 |
+
return similarity_score
|
11 |
+
|
12 |
+
# Define Gradio interface
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=calculate_similarity,
|
15 |
+
inputs=[
|
16 |
+
gr.inputs.Textbox(lines=2, placeholder="Enter first sentence..."),
|
17 |
+
gr.inputs.Textbox(lines=2, placeholder="Enter second sentence...")
|
18 |
+
],
|
19 |
+
outputs="number",
|
20 |
+
title="Sentence Similarity with WordLlama",
|
21 |
+
description="Calculate the similarity between two sentences using the WordLlama model from Hugging Face."
|
22 |
+
)
|
23 |
+
|
24 |
+
# Define five example inputs
|
25 |
+
examples = [
|
26 |
+
["I went to the car", "I went to the pawn shop"],
|
27 |
+
["The cat is on the roof", "A dog is in the yard"],
|
28 |
+
["She loves playing tennis", "She enjoys sports"],
|
29 |
+
["This is a bright day", "It's a sunny morning"],
|
30 |
+
["I bought a new phone", "I got a new mobile"]
|
31 |
+
]
|
32 |
+
|
33 |
+
iface.launch(share=True, examples=examples)
|