Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,8 @@ ast1_chunks = [(chunk, 'AST-1') for chunk in ast1_chunks]
|
|
| 41 |
ast2_chunks = [(chunk, 'AST-2') for chunk in ast2_chunks]
|
| 42 |
all_chunks = ast1_chunks + ast2_chunks
|
| 43 |
|
|
|
|
|
|
|
| 44 |
#Load the Embedding Model and LLM
|
| 45 |
from sentence_transformers import SentenceTransformer
|
| 46 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
@@ -64,6 +66,7 @@ faiss.write_index(index, 'embeddings_index.faiss')
|
|
| 64 |
# Load FAISS index
|
| 65 |
stored_index = faiss.read_index('./embeddings_index.faiss')
|
| 66 |
|
|
|
|
| 67 |
#Function to retrieve chunks
|
| 68 |
def retrieve_chunks(query, top_k=10, use_mmr=False, diversity=0.5, target_doc='AST-1'):
|
| 69 |
query_embedding = embedding_model.encode(query, convert_to_tensor=True).cpu().numpy()
|
|
@@ -118,6 +121,7 @@ def generate_response(query, retrieved_chunks):
|
|
| 118 |
def rag_system(query, use_mmr=False):
|
| 119 |
retrieved_chunks = retrieve_chunks(query, top_k=3, use_mmr=use_mmr)
|
| 120 |
response = generate_response(query, retrieved_chunks)
|
|
|
|
| 121 |
return response
|
| 122 |
|
| 123 |
import gradio as gr
|
|
|
|
| 41 |
ast2_chunks = [(chunk, 'AST-2') for chunk in ast2_chunks]
|
| 42 |
all_chunks = ast1_chunks + ast2_chunks
|
| 43 |
|
| 44 |
+
print('First 2 chunks from AST-1' + ast1_chunks[:2]) # print first 2 chunk from AST1
|
| 45 |
+
|
| 46 |
#Load the Embedding Model and LLM
|
| 47 |
from sentence_transformers import SentenceTransformer
|
| 48 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
|
|
| 66 |
# Load FAISS index
|
| 67 |
stored_index = faiss.read_index('./embeddings_index.faiss')
|
| 68 |
|
| 69 |
+
print('Stored embedding in db')
|
| 70 |
#Function to retrieve chunks
|
| 71 |
def retrieve_chunks(query, top_k=10, use_mmr=False, diversity=0.5, target_doc='AST-1'):
|
| 72 |
query_embedding = embedding_model.encode(query, convert_to_tensor=True).cpu().numpy()
|
|
|
|
| 121 |
def rag_system(query, use_mmr=False):
|
| 122 |
retrieved_chunks = retrieve_chunks(query, top_k=3, use_mmr=use_mmr)
|
| 123 |
response = generate_response(query, retrieved_chunks)
|
| 124 |
+
print(response)
|
| 125 |
return response
|
| 126 |
|
| 127 |
import gradio as gr
|