dammy commited on
Commit
d121146
·
1 Parent(s): 986cfd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -28
app.py CHANGED
@@ -25,7 +25,8 @@ 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)
30
  query_response = collection.query(query_embeddings=query_emb.tolist(), n_results=4)
31
  context = query_response['documents'][0][0]
@@ -45,38 +46,13 @@ def local_query(query, context):
45
 
46
  return tokenizer.batch_decode(outputs, skip_special_tokens=True)
47
 
48
- def generate_langchain(btn):
49
 
50
- file_name = btn.name
51
 
52
- loader = PDFMinerLoader(file_name)
53
- doc = loader.load()
54
-
55
- text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
56
- texts = text_splitter.split_documents(doc)
57
-
58
- texts = [i.page_content for i in texts]
59
-
60
- doc_emb = st_model.encode(texts)
61
- doc_emb = doc_emb.tolist()
62
-
63
- ids = [str(uuid.uuid1()) for _ in doc_emb]
64
-
65
- client = chromadb.Client()
66
- collection = client.create_collection("test_db")
67
-
68
- collection.add(
69
- embeddings=doc_emb,
70
- documents=texts,
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'
80
 
81
  print('calling local query')
82
  result = local_query(query, context)
 
25
  collection = client.create_collection("test_db")
26
 
27
 
28
+ def get_context(query_text):
29
+
30
  query_emb = st_model.encode(query_text)
31
  query_response = collection.query(query_embeddings=query_emb.tolist(), n_results=4)
32
  context = query_response['documents'][0][0]
 
46
 
47
  return tokenizer.batch_decode(outputs, skip_special_tokens=True)
48
 
 
49
 
 
50
 
51
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  def run_query(btn, history, query):
54
 
55
+ context = get_context(query)
 
56
 
57
  print('calling local query')
58
  result = local_query(query, context)