Spaces:
Sleeping
Sleeping
File size: 1,898 Bytes
69881c2 e4a5cad 69881c2 d995b49 1a3c951 707d585 800a230 707d585 1a3c951 707d585 1a3c951 707d585 1a3c951 707d585 418fa4d 707d585 418fa4d 7b79b5e 707d585 1a3c951 69881c2 |
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 |
import streamlit as st
import pandas as pd
# To make things easier later, we're also importing numpy and pandas for
# working with sample data.
from sentence_transformers import SentenceTransformer
import faiss
import numpy as np
# Load the moka-ai/m3e-base model
model = SentenceTransformer("moka-ai/m3e-base")
# Encode the documents into embeddings
documents = ["Document 1", "Document 2", "Document 3"]
document_embeddings = model.encode(documents)
# Store the embeddings to FAISS
index = faiss.IndexFlatIP(document_embeddings.shape[1])
index.add(document_embeddings)
# Encode the query into an embedding
query = "2"
query_embedding = model.encode([query])[0]
# Search the FAISS index for the most similar document
D, I = index.search(np.array([query_embedding]), k=1)
# Print the most similar document
st.write('Most similar document: ', documents[I[0][0]])
#======================================================================
st.title('My first app')
st.write("Here's our first attempt at using data to create a table:")
df = pd.DataFrame({
'first column': [1, 2, 3, 4],
'second column': [10, 20, 30, 40]
})
st.write(df)
if st.checkbox('Show dataframe'):
chart_data = pd.DataFrame(
np.random.randn(20, 3),
columns=['a', 'b', 'c'])
chart_data
option = st.selectbox(
'Which number do you like best?',
df['first column'])
st.write('You selected: ', option)
text1 = st.text('This is some text.')
if st.button('Say hello'):
st.write('Why hello there')
else:
st.write('Goodbye')
agree = st.checkbox('I agree')
if agree:
st.write('Great!')
age = st.slider('How old are you?', 0, 130, 25)
st.write("I'm ", age, 'years old')
title = st.text_input('Movie title', 'Life of Brian')
st.write('The current movie title is', title)
number = st.number_input('Insert a number')
st.write('The current number is ', number)
|