Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from langchain.embeddings import HuggingFaceHubEmbeddings
|
|
| 5 |
from langchain.vectorstores import FAISS
|
| 6 |
from langchain.llms import HuggingFaceHub
|
| 7 |
from langchain.chains import RetrievalQA
|
|
|
|
| 8 |
import os
|
| 9 |
|
| 10 |
key = os.environ.get('RLS')
|
|
@@ -34,6 +35,17 @@ def pdf_changes(pdf_doc):
|
|
| 34 |
qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=db.as_retriever(search_kwargs={"k": 3}))
|
| 35 |
return "Ready"
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def add_text(history, text):
|
| 38 |
history = history + [(text, None)]
|
| 39 |
return history, ""
|
|
@@ -63,17 +75,16 @@ title = """
|
|
| 63 |
with gr.Blocks(css=css) as demo:
|
| 64 |
with gr.Column(elem_id="col-container"):
|
| 65 |
gr.HTML(title)
|
| 66 |
-
|
| 67 |
with gr.Column():
|
| 68 |
-
pdf_doc = gr.File(label="Load a
|
| 69 |
load_pdf = gr.Button("Load PDF")
|
| 70 |
-
Books = gr.Dropdown(label="Books", choices=["Book 1", "Book 2", "Book 3"], value=["
|
| 71 |
langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
|
| 72 |
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
|
| 73 |
question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
|
| 74 |
submit_btn = gr.Button("Send message")
|
| 75 |
#load_pdf.click(loading_pdf, None, langchain_status, queue=False)
|
| 76 |
-
Books.change(
|
| 77 |
load_pdf.click(pdf_changes, inputs=[pdf_doc], outputs=[langchain_status], queue=False)
|
| 78 |
question.submit(add_text, [chatbot, question], [chatbot, question]).then(
|
| 79 |
bot, chatbot, chatbot
|
|
|
|
| 5 |
from langchain.vectorstores import FAISS
|
| 6 |
from langchain.llms import HuggingFaceHub
|
| 7 |
from langchain.chains import RetrievalQA
|
| 8 |
+
from datasets import load_dataset
|
| 9 |
import os
|
| 10 |
|
| 11 |
key = os.environ.get('RLS')
|
|
|
|
| 35 |
qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=db.as_retriever(search_kwargs={"k": 3}))
|
| 36 |
return "Ready"
|
| 37 |
|
| 38 |
+
def book_changes(book):
|
| 39 |
+
|
| 40 |
+
with open( book, 'rb') as f:
|
| 41 |
+
data = pickle.load(f)
|
| 42 |
+
llm=HuggingFaceHub(repo_id="google/flan-t5-xxl", model_kwargs={"temperature":1, "max_length":1000000})
|
| 43 |
+
global qa
|
| 44 |
+
qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=db.as_retriever(search_kwargs={"k": 3}))
|
| 45 |
+
return "Ready"
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
def add_text(history, text):
|
| 50 |
history = history + [(text, None)]
|
| 51 |
return history, ""
|
|
|
|
| 75 |
with gr.Blocks(css=css) as demo:
|
| 76 |
with gr.Column(elem_id="col-container"):
|
| 77 |
gr.HTML(title)
|
|
|
|
| 78 |
with gr.Column():
|
| 79 |
+
pdf_doc = gr.File(label="Load a PDF", file_types=['.pdf'], type="file")
|
| 80 |
load_pdf = gr.Button("Load PDF")
|
| 81 |
+
Books = gr.Dropdown(label="Books", choices=["Book 1", "Book 2", "Book 3"], value=["https://huggingface.co/datasets/SCLRM/pdf_chatbot/blob/main/embeddings/embeddings.pickle", "Book 2", "Book 3"])
|
| 82 |
langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
|
| 83 |
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
|
| 84 |
question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
|
| 85 |
submit_btn = gr.Button("Send message")
|
| 86 |
#load_pdf.click(loading_pdf, None, langchain_status, queue=False)
|
| 87 |
+
Books.change(book_changes, inputs=[Books], outputs=[langchain_status], queue=False)
|
| 88 |
load_pdf.click(pdf_changes, inputs=[pdf_doc], outputs=[langchain_status], queue=False)
|
| 89 |
question.submit(add_text, [chatbot, question], [chatbot, question]).then(
|
| 90 |
bot, chatbot, chatbot
|