fffiloni commited on
Commit
4228512
β€’
1 Parent(s): 596e8fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -17,7 +17,7 @@ from langchain.chains import RetrievalQA
17
  def loading_pdf():
18
  return "Loading..."
19
 
20
- def pdf_changes(pdf_doc):
21
 
22
  loader = OnlinePDFLoader(pdf_doc.name)
23
  documents = loader.load()
@@ -26,7 +26,7 @@ def pdf_changes(pdf_doc):
26
  embeddings = HuggingFaceHubEmbeddings()
27
  db = Chroma.from_documents(texts, embeddings)
28
  retriever = db.as_retriever()
29
- llm = HuggingFaceHub(repo_id="google/flan-ul2", model_kwargs={"temperature":0.1, "max_new_tokens":300})
30
  global qa
31
  qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents=True)
32
  return "Ready"
@@ -66,6 +66,7 @@ with gr.Blocks(css=css) as demo:
66
 
67
  with gr.Column():
68
  pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
 
69
  with gr.Row():
70
  langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
71
  load_pdf = gr.Button("Load pdf to langchain")
@@ -73,8 +74,9 @@ with gr.Blocks(css=css) as demo:
73
  chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
74
  question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
75
  submit_btn = gr.Button("Send message")
76
- load_pdf.click(loading_pdf, None, langchain_status, queue=False)
77
- load_pdf.click(pdf_changes, pdf_doc, langchain_status, queue=False)
 
78
  question.submit(add_text, [chatbot, question], [chatbot, question]).then(
79
  bot, chatbot, chatbot
80
  )
 
17
  def loading_pdf():
18
  return "Loading..."
19
 
20
+ def pdf_changes(pdf_doc, repo_id):
21
 
22
  loader = OnlinePDFLoader(pdf_doc.name)
23
  documents = loader.load()
 
26
  embeddings = HuggingFaceHubEmbeddings()
27
  db = Chroma.from_documents(texts, embeddings)
28
  retriever = db.as_retriever()
29
+ llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature":0.1, "max_new_tokens":300})
30
  global qa
31
  qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents=True)
32
  return "Ready"
 
66
 
67
  with gr.Column():
68
  pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
69
+ repo_id = gr.Dropdown(label="LLM", choices=["google/flan-ul2", "stabilityai/stablelm-tuned-alpha-3b", "databricks/dolly-v2-3b", "Writer/camel-5b-hf" ], value="google/flan-ul2")
70
  with gr.Row():
71
  langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
72
  load_pdf = gr.Button("Load pdf to langchain")
 
74
  chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
75
  question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
76
  submit_btn = gr.Button("Send message")
77
+ #load_pdf.click(loading_pdf, None, langchain_status, queue=False)
78
+ repo_id.change(pdf_changes, inputs=[pdf_doc, repo_id], langchain_status, queue=False)
79
+ load_pdf.click(pdf_changes, inputs=[pdf_doc, repo_id], langchain_status, queue=False)
80
  question.submit(add_text, [chatbot, question], [chatbot, question]).then(
81
  bot, chatbot, chatbot
82
  )