NAB1108 commited on
Commit
031e23f
·
1 Parent(s): e966e65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -28,12 +28,12 @@ from langchain.document_loaders import PyPDFLoader
28
  from langchain.indexes import VectorstoreIndexCreator
29
  import tempfile
30
 
31
- os.environ["OPENAI_API_KEY"] = "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"
32
  query1=" "
33
  def loading_pdf():
34
  return "Loading..."
35
 
36
- def pdf_changes(pdf_doc, repo_id):
37
 
38
  loader = OnlinePDFLoader(pdf_doc.name)
39
  documents = loader.load()
@@ -56,7 +56,7 @@ def pdf_changes(pdf_doc, repo_id):
56
  )
57
 
58
 
59
- system_template="""You are a helpful chatbot used by the user to chat with pdf documents. Only answer the questions by using information provided in the context provided to you. If there is no relavant context, tell 'Hmm, I'm not sure'.
60
  ----------------
61
  {summaries}"""
62
 
@@ -92,7 +92,7 @@ def bot(history):
92
 
93
  def infer(question):
94
  global query1
95
- openai.api_key = "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"
96
  prompt_text = question
97
  if prompt_text:
98
  query1 = query1 + "\nUser: " + prompt_text + "\nBot: "
@@ -112,9 +112,9 @@ css="""
112
  """
113
 
114
  title = """
115
- <div style="text-align: center;max-width: 700px;">
116
- <h1>Chat with PDF</h1>
117
- <p style="text-align: center;">Upload a .PDF from your computer, click the "Load PDF" button, <br />
118
  when everything is ready, you can start asking questions about the pdf ;)</p>
119
  </div>
120
  """
@@ -122,10 +122,11 @@ title = """
122
 
123
  with gr.Blocks(css=css,theme = gr.themes.Soft()) as demo:
124
  with gr.Column(elem_id="col-container"):
125
- # gr.HTML(title)
126
 
127
  with gr.Column():
128
  pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
 
129
  #repo_id = gr.Dropdown(label="LLM", choices=["google/flan-ul2", "OpenAssistant/oasst-sft-1-pythia-12b", "bigscience/bloomz"], value="google/flan-ul2")
130
  with gr.Row():
131
  langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
@@ -136,7 +137,7 @@ with gr.Blocks(css=css,theme = gr.themes.Soft()) as demo:
136
  submit_btn = gr.Button("Send message")
137
  #load_pdf.click(loading_pdf, None, langchain_status, queue=False)
138
  #repo_id.change(pdf_changes, inputs=[pdf_doc], outputs=[langchain_status], queue=False)
139
- load_pdf.click(pdf_changes, inputs=[pdf_doc], outputs=[langchain_status], queue=False)
140
  question.submit(add_text, [chatbot, question], [chatbot, question]).then(
141
  bot, chatbot, chatbot
142
  )
@@ -144,4 +145,4 @@ with gr.Blocks(css=css,theme = gr.themes.Soft()) as demo:
144
  bot, chatbot, chatbot
145
  )
146
 
147
- demo.launch()
 
28
  from langchain.indexes import VectorstoreIndexCreator
29
  import tempfile
30
 
31
+ os.environ["OPENAI_API_KEY"] = "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"
32
  query1=" "
33
  def loading_pdf():
34
  return "Loading..."
35
 
36
+ def pdf_changes(pdf_doc, prompt):
37
 
38
  loader = OnlinePDFLoader(pdf_doc.name)
39
  documents = loader.load()
 
56
  )
57
 
58
 
59
+ system_template="""You are a helpful chatbot used by the user to chat with pdf documents. Only answer the questions by using information provided in the context provided to you. If there is no relavant context, tell 'Hmm, I'm not sure'."""+prompt+"""
60
  ----------------
61
  {summaries}"""
62
 
 
92
 
93
  def infer(question):
94
  global query1
95
+ openai.api_key = "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"
96
  prompt_text = question
97
  if prompt_text:
98
  query1 = query1 + "\nUser: " + prompt_text + "\nBot: "
 
112
  """
113
 
114
  title = """
115
+ <div style="text-align: center; max-width: 700px;">
116
+ <h1 style="color: #4545FF;">Chat with PDF</h1>
117
+ <p style="text-align: center; color: #4545FF;">Upload a .PDF from your computer, click the "Load PDF" button, <br />
118
  when everything is ready, you can start asking questions about the pdf ;)</p>
119
  </div>
120
  """
 
122
 
123
  with gr.Blocks(css=css,theme = gr.themes.Soft()) as demo:
124
  with gr.Column(elem_id="col-container"):
125
+ #gr.HTML(title)
126
 
127
  with gr.Column():
128
  pdf_doc = gr.File(label="Load a pdf", file_types=['.pdf'], type="file")
129
+ prompt = gr.Textbox(label="Behaviour Prompt", placeholder="Reply to all questions as a rap / Reply to all questions in Hindi etc. ")
130
  #repo_id = gr.Dropdown(label="LLM", choices=["google/flan-ul2", "OpenAssistant/oasst-sft-1-pythia-12b", "bigscience/bloomz"], value="google/flan-ul2")
131
  with gr.Row():
132
  langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
 
137
  submit_btn = gr.Button("Send message")
138
  #load_pdf.click(loading_pdf, None, langchain_status, queue=False)
139
  #repo_id.change(pdf_changes, inputs=[pdf_doc], outputs=[langchain_status], queue=False)
140
+ load_pdf.click(pdf_changes, inputs=[pdf_doc,prompt], outputs=[langchain_status], queue=False)
141
  question.submit(add_text, [chatbot, question], [chatbot, question]).then(
142
  bot, chatbot, chatbot
143
  )
 
145
  bot, chatbot, chatbot
146
  )
147
 
148
+ demo.launch(debug=True)