WeyinmiA commited on
Commit
54fe868
Β·
1 Parent(s): d2cd6b7

Reupload changed app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -21
app.py CHANGED
@@ -23,7 +23,6 @@ import time
23
  import shutil
24
 
25
 
26
-
27
  #env_path = Path('.') / 'environ_vars.env'
28
  #load_dotenv(dotenv_path=env_path)
29
  # Print variable FOO to test if this worked
@@ -32,8 +31,6 @@ import shutil
32
  openai.api_key = os.environ['OPENAI_API_KEY']
33
  hf_token = os.environ['HUGGINGFACEHUB_API_TOKEN']
34
 
35
- def loading_pdf_message():
36
- return "Pdf(s) loading..."
37
 
38
  def augment_llm_with_docs(files):
39
  from langchain.document_loaders import PyPDFLoader
@@ -116,7 +113,6 @@ def augment_llm_with_docs(files):
116
  memory=memory
117
  )
118
 
119
- return "Pdf(s) loaded"
120
 
121
  def respond(message, chat_history):
122
  result = qa({"question": message})
@@ -126,23 +122,15 @@ def respond(message, chat_history):
126
  return "", chat_history
127
 
128
  with gr.Blocks() as demo:
129
- with gr.Column():
130
- upload_pdfs = gr.File(file_types=[".pdf"], file_count="multiple")
131
- with gr.Row():
132
- status_vec_db = gr.Textbox(label="DB status", placeholder="This will show status of pdf database", interactive=False)
133
- load_pdfs = gr.Button("Load pdf(s) to database")
134
-
135
-
136
  chatbot = gr.Chatbot()
137
- prompt_msg = gr.Textbox(label="Prompt")
138
- submit_btn = gr.Button("Submit")
139
- clear = gr.ClearButton([prompt_msg, chatbot])
140
-
141
- #upload_pdfs.upload(augment_llm_with_docs, inputs=upload_pdfs)
142
- load_pdfs.click(loading_pdf_message, None, status_vec_db)
143
- load_pdfs.click(augment_llm_with_docs, inputs=upload_pdfs, outputs=status_vec_db)
144
- submit_btn.click(respond, inputs=[prompt_msg, chatbot], outputs=[prompt_msg, chatbot])
145
- prompt_msg.submit(respond, inputs=[prompt_msg, chatbot], outputs=[prompt_msg, chatbot])
146
 
147
  gr.Markdown("## Input Pdf File Examples")
148
  gr.Examples(examples=["docs/finance/Week_1_Intro.pdf",
@@ -157,4 +145,4 @@ with gr.Blocks() as demo:
157
  first ask these questions, then dive deeper into the topics such as asking to know more about the time
158
  value of money.""")
159
 
160
- demo.launch()
 
23
  import shutil
24
 
25
 
 
26
  #env_path = Path('.') / 'environ_vars.env'
27
  #load_dotenv(dotenv_path=env_path)
28
  # Print variable FOO to test if this worked
 
31
  openai.api_key = os.environ['OPENAI_API_KEY']
32
  hf_token = os.environ['HUGGINGFACEHUB_API_TOKEN']
33
 
 
 
34
 
35
  def augment_llm_with_docs(files):
36
  from langchain.document_loaders import PyPDFLoader
 
113
  memory=memory
114
  )
115
 
 
116
 
117
  def respond(message, chat_history):
118
  result = qa({"question": message})
 
122
  return "", chat_history
123
 
124
  with gr.Blocks() as demo:
125
+ upload_pdfs = gr.File(file_types=[".pdf"], file_count="multiple")
 
 
 
 
 
 
126
  chatbot = gr.Chatbot()
127
+ msg = gr.Textbox(label="Prompt")
128
+ btn = gr.Button("Submit")
129
+ clear = gr.ClearButton([msg, chatbot, upload_pdfs])
130
+
131
+ upload_pdfs.upload(augment_llm_with_docs, inputs=upload_pdfs)
132
+ btn.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
133
+ msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
 
 
134
 
135
  gr.Markdown("## Input Pdf File Examples")
136
  gr.Examples(examples=["docs/finance/Week_1_Intro.pdf",
 
145
  first ask these questions, then dive deeper into the topics such as asking to know more about the time
146
  value of money.""")
147
 
148
+ demo.launch()