Spaces:
Sleeping
Sleeping
Commit
·
2af3209
1
Parent(s):
730c378
adding chatbot
Browse files
app.py
CHANGED
@@ -49,7 +49,6 @@ def summarize_contents():
|
|
49 |
return qa.run(question)
|
50 |
|
51 |
def document_loader(file_path,api_key,doc_type='pdf',llm='Huggingface'):
|
52 |
-
embedding_model = SentenceTransformerEmbeddings(model_name='all-mpnet-base-v2',model_kwargs={"device": DEVICE})
|
53 |
document = None
|
54 |
if doc_type == 'pdf':
|
55 |
document = process_pdf_document(document_file=file_path)
|
@@ -60,6 +59,7 @@ def document_loader(file_path,api_key,doc_type='pdf',llm='Huggingface'):
|
|
60 |
elif doc_type == 'word':
|
61 |
document = process_word_document(document_file=file_path)
|
62 |
if document:
|
|
|
63 |
texts = process_documents(documents=document)
|
64 |
vector_db = FAISS.from_documents(documents=texts, embedding= embedding_model)
|
65 |
global qa
|
@@ -72,7 +72,7 @@ def document_loader(file_path,api_key,doc_type='pdf',llm='Huggingface'):
|
|
72 |
else:
|
73 |
return "Error in loading Documents "
|
74 |
|
75 |
-
return "
|
76 |
|
77 |
|
78 |
def process_text_document(document_file):
|
@@ -143,8 +143,14 @@ with gr.Blocks(css=css) as demo:
|
|
143 |
|
144 |
summarize_pdf.click(summarize_contents,outputs=summary)
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
|
150 |
demo.launch()
|
|
|
49 |
return qa.run(question)
|
50 |
|
51 |
def document_loader(file_path,api_key,doc_type='pdf',llm='Huggingface'):
|
|
|
52 |
document = None
|
53 |
if doc_type == 'pdf':
|
54 |
document = process_pdf_document(document_file=file_path)
|
|
|
59 |
elif doc_type == 'word':
|
60 |
document = process_word_document(document_file=file_path)
|
61 |
if document:
|
62 |
+
embedding_model = SentenceTransformerEmbeddings(model_name='thenlper/gte-base',model_kwargs={"device": DEVICE})
|
63 |
texts = process_documents(documents=document)
|
64 |
vector_db = FAISS.from_documents(documents=texts, embedding= embedding_model)
|
65 |
global qa
|
|
|
72 |
else:
|
73 |
return "Error in loading Documents "
|
74 |
|
75 |
+
return "Document processing complete-Embeddings Created "
|
76 |
|
77 |
|
78 |
def process_text_document(document_file):
|
|
|
143 |
|
144 |
summarize_pdf.click(summarize_contents,outputs=summary)
|
145 |
|
146 |
+
with gr.Column():
|
147 |
+
with gr.Row():
|
148 |
+
chatbot = gr.Chatbot(height=300)
|
149 |
+
sources = gr.HTML(value = "Source paragraphs where I looked for answers will appear here", height=300)
|
150 |
+
|
151 |
+
with gr.Row():
|
152 |
+
message = gr.Textbox(label="Type your question?",lines=1).style(full_width=False)
|
153 |
+
submit_query = gr.Button(value="Send message", variant="secondary", scale = 1)
|
154 |
+
|
155 |
|
156 |
demo.launch()
|