Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -291,33 +291,6 @@ def upload_and_prepare_old(file,user):
|
|
| 291 |
return mm, pdf_links # Update both outputs
|
| 292 |
#return mm
|
| 293 |
#create_faiss_index(repo_id, file_input)
|
| 294 |
-
#======================================================================
|
| 295 |
-
def get_document_summary(repo_id,query,llm=None):
|
| 296 |
-
"""Generate summary of all documents in repo"""
|
| 297 |
-
try:
|
| 298 |
-
# Load vectorstore
|
| 299 |
-
embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 300 |
-
faiss_path = hf_hub_download(repo_id=repo_id, filename="index.faiss", repo_type="dataset")
|
| 301 |
-
vectorstore = FAISS.load_local(os.path.dirname(faiss_path), embeddings, allow_dangerous_deserialization=True)
|
| 302 |
-
|
| 303 |
-
# Get top documents
|
| 304 |
-
docs = vectorstore.similarity_search(query, k=20)
|
| 305 |
-
context = "\n".join([doc.page_content[:200] for doc in docs])
|
| 306 |
-
|
| 307 |
-
# Summarize with your LLM
|
| 308 |
-
summary_prompt = f"""
|
| 309 |
-
Summarize these context:
|
| 310 |
-
|
| 311 |
-
{context[:3000]}
|
| 312 |
-
|
| 313 |
-
Summary:
|
| 314 |
-
"""
|
| 315 |
-
summary = llm(summary_prompt) # Uses TinyLlama
|
| 316 |
-
return summary
|
| 317 |
-
except:
|
| 318 |
-
return "Summary unavailable"
|
| 319 |
-
|
| 320 |
-
|
| 321 |
#======================================================================
|
| 322 |
def generate_qa_chain(repo_id, embedding_model="sentence-transformers/all-MiniLM-L6-v2", llm=None):
|
| 323 |
"""
|
|
@@ -516,10 +489,6 @@ with gr.Blocks(title="N R L C H A T B O T - for commercial procurement - Supply"
|
|
| 516 |
ask_question1,
|
| 517 |
inputs=query_input1,
|
| 518 |
outputs=answer_output1
|
| 519 |
-
).then( # Auto-trigger after answer
|
| 520 |
-
get_document_summary,
|
| 521 |
-
inputs=[repo_id,query_input1,llm1],
|
| 522 |
-
outputs=summary_output
|
| 523 |
)
|
| 524 |
|
| 525 |
with gr.Row():
|
|
|
|
| 291 |
return mm, pdf_links # Update both outputs
|
| 292 |
#return mm
|
| 293 |
#create_faiss_index(repo_id, file_input)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
#======================================================================
|
| 295 |
def generate_qa_chain(repo_id, embedding_model="sentence-transformers/all-MiniLM-L6-v2", llm=None):
|
| 296 |
"""
|
|
|
|
| 489 |
ask_question1,
|
| 490 |
inputs=query_input1,
|
| 491 |
outputs=answer_output1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 492 |
)
|
| 493 |
|
| 494 |
with gr.Row():
|