Spaces:
Running
Running
import streamlit as st # type: ignore | |
from PIL import Image | |
import os | |
import ast | |
import contextlib | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from sklearn.manifold import TSNE | |
from sentence_transformers import SentenceTransformer | |
from sklearn.metrics.pairwise import cosine_similarity | |
from translate_app import tr | |
title = "Sentence Similarity" | |
sidebar_name = "Sentence Similarity" | |
dataPath = st.session_state.DataPath | |
def run(): | |
st.write("") | |
st.write("") | |
st.title(tr(title)) | |
sentences = ["This is an example sentence", "Each sentence is converted"] | |
sentences[0] = st.text_area(label=tr("Saisir un élément issu de la proposition de valeur (quelque soit la langue):"), value="This is an example sentence") | |
sentences[1] = st.text_area(label=tr("Saisir une phrase issue de l'acte de vente (quelque soit la langue):"), value="Each sentence is converted", height=200) | |
st.button(label=tr("Validez"), type="primary") | |
model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2') | |
embeddings = model.encode(sentences) | |
st.write(tr("Transformation de chaque phrase en vecteur (dimension = 384 ):")) | |
st.write(embeddings) | |
st.write("") | |
# Calculate cosine similarity between the two sentences | |
similarity = cosine_similarity([embeddings[0]], [embeddings[1]]) | |
st.write(tr("**Cosine similarity** comprise entre 0 et 1 :"), similarity[0][0]) | |
st.write("") | |
st.write("") | |
st.write("") |