Pablo276 commited on
Commit
85b7467
1 Parent(s): a421ba7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.vectorstores import faiss
3
+ from langchain.text_splitter import CharacterTextSplitter
4
+ from langchain.embeddings import OpenAIEmbeddings, HuggingFaceInstructEmbeddings
5
+ from langchain.vectorstores import FAISS
6
+ from langchain.document_loaders import TextLoader
7
+ from langchain.embeddings import SentenceTransformerEmbeddings
8
+ from tempfile import NamedTemporaryFile
9
+ import os
10
+ import shutil
11
+
12
+ try:
13
+ shutil.rmtree("tempDir")
14
+ except :
15
+ pass
16
+ try:
17
+ os.mkdir("tempDir")
18
+ except:
19
+ pass
20
+ def save_uploadedfile(uploadedfile):
21
+
22
+ with open(os.path.join("tempDir",uploadedfile.name),"wb") as f:
23
+ f.write(uploadedfile.getbuffer())
24
+ return st.success("Saved File:{} to tempDir".format(uploadedfile.name))
25
+
26
+
27
+ def main():
28
+ st.set_page_config(page_title="chet with unipv")
29
+ st.text_input("fai una domanda al tuo professore ")
30
+ with st.sidebar:
31
+ st.subheader("Your_faiss_index")
32
+ documents=st.file_uploader("upload your faiss index here ",accept_multiple_files=True)
33
+ if st.button("Procedi"):
34
+ for document in documents:
35
+ save_uploadedfile(document)
36
+ #with st.spinner("sto processando i tuoi dati"):
37
+ print(documents)
38
+ query="chi è matteo salvini?"
39
+ embeddings= HuggingFaceInstructEmbeddings(model_name="thenlper/gte-base")
40
+ new_db = FAISS.load_local("tempDir", embeddings)
41
+ docs = new_db.similarity_search(query)
42
+ print(docs)
43
+ if __name__=="__main__":
44
+ main()