lekkalar commited on
Commit
06a82b5
1 Parent(s): 1d13553

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -34
app.py CHANGED
@@ -9,10 +9,8 @@ from langchain.vectorstores import Chroma # for the vectorization part
9
  from langchain.chains import RetrievalQA # for conversing with chatGPT
10
  from langchain.chat_models import ChatOpenAI # the LLM model we'll use (ChatGPT)
11
 
12
- def loading_pdf():
13
- return "Loading..."
14
 
15
- def pdf_changes(pdf_doc, open_ai_key):
16
  if openai_key is not None:
17
  os.environ['OPENAI_API_KEY'] = open_ai_key
18
  #Load the pdf file
@@ -36,40 +34,33 @@ def pdf_changes(pdf_doc, open_ai_key):
36
 
37
  def answer_query(query):
38
  question = query
39
- return pdf_qa.run(question)
 
40
 
41
- css="""
42
- #col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
43
- """
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- title = """
46
- <div style="text-align: center;max-width: 700px;">
47
- <h1>Chatbot for PDFs - GPT-4</h1>
48
- <p style="text-align: center;">Upload a .PDF, click the "Load PDF to LangChain" button, <br />
49
- Wait for the Status to show Ready, start typing your questions. <br />
50
- The app is built on GPT-4</p>
51
- </div>
52
- """
53
 
 
 
 
 
54
 
55
- with gr.Blocks(css=css) as demo:
56
- with gr.Column(elem_id="col-container"):
57
- gr.HTML(title)
58
-
59
- with gr.Column():
60
- openai_key = gr.Textbox(label="Your GPT-4 OpenAI API key", type="password")
61
- pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
62
- with gr.Row():
63
- langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
64
- load_pdf = gr.Button("Load PDF to LangChain")
65
-
66
- chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
67
- question = gr.Textbox(label="Question", placeholder="Type your question and hit Enter ")
68
- submit_btn = gr.Button("Send Message")
69
-
70
- load_pdf.click(loading_pdf, None, langchain_status, queue=False)
71
- load_pdf.click(pdf_changes, inputs=[pdf_doc, openai_key], outputs=[langchain_status], queue=False)
72
- submit_btn.click(answer_query,question,chatbot)
73
-
74
 
75
  demo.launch()
 
9
  from langchain.chains import RetrievalQA # for conversing with chatGPT
10
  from langchain.chat_models import ChatOpenAI # the LLM model we'll use (ChatGPT)
11
 
 
 
12
 
13
+ def load_pdf(pdf_doc, open_ai_key):
14
  if openai_key is not None:
15
  os.environ['OPENAI_API_KEY'] = open_ai_key
16
  #Load the pdf file
 
34
 
35
  def answer_query(query):
36
  question = query
37
+ return chain.run(question)
38
+
39
 
40
+ html = """
41
+ <div style="text-align:center; max width: 700px;">
42
+ <h1>ChatPDF</h1>
43
+ <p> Upload a PDF File, then click on Load PDF File <br>
44
+ Once the document has been loaded you can begin chatting with the PDF =)
45
+ </div>"""
46
+ css = """container{max-width:700px; margin-left:auto; margin-right:auto,padding:20px}"""
47
+ with gr.Blocks(css=css,theme=gr.themes.Monochrome()) as demo:
48
+ gr.HTML(html)
49
+ with gr.Column():
50
+ gr.Markdown('ChatPDF')
51
+ pdf_doc = gr.File(label="Load a pdf",file_types=['.pdf','.docx'],type='file')
52
+ with gr.Row():
53
+ load_pdf = gr.Button('Load pdf file')
54
+ status = gr.Textbox(label="Status",placeholder='',interactive=False)
55
 
 
 
 
 
 
 
 
 
56
 
57
+ with gr.Row():
58
+ input = gr.Textbox(label="type in your question")
59
+ output = gr.Textbox(label="output")
60
+ submit_query = gr.Button("submit")
61
 
62
+ load_pdf.click(load_pdf,inputs=pdf_doc,outputs=status)
63
+
64
+ submit_query.click(answer_query,input,output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  demo.launch()