File size: 4,279 Bytes
50fdd96
062d5b7
 
 
50fdd96
 
964330b
062d5b7
50fdd96
f39ded6
948505c
50fdd96
 
964330b
 
d394b95
 
 
f39ded6
 
 
d394b95
50fdd96
 
 
d394b95
 
 
 
 
46097de
d394b95
 
 
 
 
f39ded6
 
 
d394b95
 
50fdd96
 
062d5b7
948505c
964330b
062d5b7
f39ded6
 
 
 
 
 
c92b6f6
3130d5c
4297bcd
68721f5
d394b95
 
 
 
 
 
 
 
 
224143d
 
 
 
 
 
f39ded6
 
 
224143d
 
 
 
 
 
f39ded6
 
 
224143d
 
 
 
 
 
f39ded6
 
 
224143d
 
 
d394b95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import numpy as np
import gradio as gr
from sentence_transformers import SentenceTransformer, util

# Function to load the selected model
def load_model(model_name):
    return SentenceTransformer(model_name)

# Function to compute similarity and classify relationship
def predict(model_name_display, original_sentence_input, sentence_1=None, sentence_2=None, sentence_3=None, sentence_4=None, sentence_5=None):
    model_name = "sartifyllc/African-Cross-Lingua-Embeddings-Model"
    model = load_model(model_name)
    result = {
        "Model Name": model_name,
        "Original Sentence": original_sentence_input,
        "Sentences to Compare": {
            "Sentence 1": sentence_1,
            "Sentence 2": sentence_2,
            "Sentence 3": sentence_3,
            "Sentence 4": sentence_4,
            "Sentence 5": sentence_5
        },
        "Similarity Scores": {}
    }
    
    if not sentence_1 or not sentence_2 or not sentence_3:
        return "Please provide a minimum of three sentences for comparison.", {}
    if not original_sentence_input:
        return "Please provide the original sentence.", {}
    
    sentences = [original_sentence_input, sentence_1, sentence_2, sentence_3,sentence_4,sentence_5]
    embeddings = model.encode(sentences)
    similarities = util.cos_sim(embeddings[0], embeddings[1:])
    similarity_scores = {
        "Sentence 1": float(similarities[0, 0]),
        "Sentence 2": float(similarities[0, 1]),
        "Sentence 3": float(similarities[0, 2]),
        "Sentence 4": float(similarities[0, 3]),
         "Sentence 5": float(similarities[0, 4]),
    }
    result["Similarity Scores"] = similarity_scores
    
    return result

model_name_display = gr.Markdown(value="**Model Name**: sartifyllc/African-Cross-Lingua-Embeddings-Model")
original_sentence_input = gr.Textbox(lines=2, placeholder="Enter the original sentence here...", label="Original Sentence")

sentence_1 = gr.Textbox(lines=2, placeholder="Enter the sentence to compare here...", label="Sentence 1")
sentence_2 = gr.Textbox(lines=2, placeholder="Enter the sentence to compare here...", label="Sentence 2")
sentence_3 = gr.Textbox(lines=2, placeholder="Enter the sentence to compare here...", label="Sentence 3")
sentence_4 = gr.Textbox(lines=2, placeholder="Enter the sentence to compare here...", label="Sentence 4")
sentence_5 = gr.Textbox(lines=2, placeholder="Enter the sentence to compare here...", label="Sentence 5")


inputs = [model_name_display, original_sentence_input, sentence_1, sentence_2, sentence_3,sentence_4,sentence_5]
outputs = gr.JSON(label="Detailed Similarity Scores")

# Create Gradio interface
gr.Interface(
    fn=predict,
    title="African Cross-Lingua Embeddings Model's Demo",
    description="Compute the semantic similarity across various sentences among any African Languages using African-Cross-Lingua-Embeddings-Model.",
    inputs=inputs,  
    outputs=outputs,
    cache_examples=False,
    article="Author: Innocent Charles. Model from Hugging Face Hub (sartify.com): [sartifyllc/African-Cross-Lingua-Embeddings-Model](https://huggingface.co/sartifyllc/African-Cross-Lingua-Embeddings-Model)",
  examples = [
    [
        "sartifyllc/African-Cross-Lingua-Embeddings-Model",
        "Jua linawaka sana leo.",
        "Òrùlé jẹ́ tí ó ti máa ń tan-ìmólẹ̀ lónìí.",
        "Ran na haske sosai yau.",
        "The sun is shining brightly today.",
        "napenda sana jua",
        "schooling is kinda boring, I don't like it"
    ],
    [
        "sartifyllc/African-Cross-Lingua-Embeddings-Model",
        "Mbuzi anaruka juu ya uzio.",
        "Àgbò ohun ti ń kọjú wá sórí orí-ọ̀kẹ́.",
        "Kura mai sauri tana tsalle kan kare mai barci.",
        "The goat is jumping over the fence.",
        "Àgbò ohun ti ń kọjú wá sórí orí-ọ̀kẹ́.",
        "The cat is sleeping under the table."
    ],
    [
        "sartifyllc/African-Cross-Lingua-Embeddings-Model",
        "Ninapenda kujifunza lugha mpya.",
        "Mo nífẹ̀ẹ́ láti kọ́ èdè tuntun.",
        "Ina son koyon sababbin harsuna.",
        "I love learning new languages.",
        "Ina son koyon sababbin harsuna.",
        "botu neyle ki lo no"
    ]
]

).launch(debug=True, share=True)