Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,9 @@ ST_name = 'sentence-transformers/sentence-t5-base'
|
|
21 |
st_model = SentenceTransformer(ST_name)
|
22 |
print('sentence read')
|
23 |
|
|
|
|
|
|
|
24 |
|
25 |
def get_context(query_text, collection):
|
26 |
query_emb = st_model.encode(query_text)
|
@@ -42,8 +45,7 @@ def local_query(query, context):
|
|
42 |
|
43 |
return tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
44 |
|
45 |
-
def
|
46 |
-
|
47 |
|
48 |
file_name = btn.name
|
49 |
|
@@ -69,8 +71,9 @@ def run_query(btn, history, query):
|
|
69 |
ids=ids
|
70 |
)
|
71 |
|
72 |
-
|
73 |
-
|
|
|
74 |
|
75 |
# context = get_context(query, collection)
|
76 |
context = 'My name is damla'
|
@@ -94,6 +97,31 @@ def run_query(btn, history, query):
|
|
94 |
def upload_pdf(file):
|
95 |
try:
|
96 |
if file is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
return 'Successfully uploaded!'
|
99 |
else:
|
|
|
21 |
st_model = SentenceTransformer(ST_name)
|
22 |
print('sentence read')
|
23 |
|
24 |
+
client = chromadb.Client()
|
25 |
+
collection = client.create_collection("test_db")
|
26 |
+
|
27 |
|
28 |
def get_context(query_text, collection):
|
29 |
query_emb = st_model.encode(query_text)
|
|
|
45 |
|
46 |
return tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
47 |
|
48 |
+
def generate_langchain(btn):
|
|
|
49 |
|
50 |
file_name = btn.name
|
51 |
|
|
|
71 |
ids=ids
|
72 |
)
|
73 |
|
74 |
+
return collection
|
75 |
+
|
76 |
+
def run_query(btn, history, query):
|
77 |
|
78 |
# context = get_context(query, collection)
|
79 |
context = 'My name is damla'
|
|
|
97 |
def upload_pdf(file):
|
98 |
try:
|
99 |
if file is not None:
|
100 |
+
|
101 |
+
global collection
|
102 |
+
|
103 |
+
file_name = btn.name
|
104 |
+
|
105 |
+
loader = PDFMinerLoader(file_name)
|
106 |
+
doc = loader.load()
|
107 |
+
|
108 |
+
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
109 |
+
texts = text_splitter.split_documents(doc)
|
110 |
+
|
111 |
+
texts = [i.page_content for i in texts]
|
112 |
+
|
113 |
+
doc_emb = st_model.encode(texts)
|
114 |
+
doc_emb = doc_emb.tolist()
|
115 |
+
|
116 |
+
ids = [str(uuid.uuid1()) for _ in doc_emb]
|
117 |
+
|
118 |
+
|
119 |
+
collection.add(
|
120 |
+
embeddings=doc_emb,
|
121 |
+
documents=texts,
|
122 |
+
ids=ids
|
123 |
+
)
|
124 |
+
|
125 |
|
126 |
return 'Successfully uploaded!'
|
127 |
else:
|