bhaskartripathi commited on
Commit
faecfdf
·
1 Parent(s): 11848f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -25
app.py CHANGED
@@ -7,10 +7,6 @@ import openai
7
  import gradio as gr
8
  import os
9
  from sklearn.neighbors import NearestNeighbors
10
- #import tensorflow as tf
11
- import tensorflow.compat.v1 as tf
12
- tf.disable_v2_behavior()
13
-
14
 
15
  def download_pdf(url, output_path):
16
  urllib.request.urlretrieve(url, output_path)
@@ -136,15 +132,14 @@ def generate_answer(question,openAI_key):
136
  return answer
137
 
138
 
139
- def question_answer(url, file, question, openAI_key, history=[]):
140
- if openAI_key.strip() == '':
141
- return '[ERROR]: Please enter your Open AI Key. Get your key here: https://platform.openai.com/account/api-keys'
142
-
143
- if url.strip() == '' and file is None:
144
- return '[ERROR]: Both URL and PDF are empty. Provide at least one.'
145
-
146
- if url.strip() != '' and file is not None:
147
- return '[ERROR]: Both URL and PDF are provided. Please provide only one (either URL or PDF).'
148
 
149
  if url.strip() != '':
150
  glob_url = url
@@ -161,17 +156,13 @@ def question_answer(url, file, question, openAI_key, history=[]):
161
  if question.strip() == '':
162
  return '[ERROR]: Question field is empty'
163
 
164
- answer = generate_answer(question, openAI_key)
165
- history.append({'question': question, 'answer': answer})
166
- return answer
167
-
168
 
169
 
170
  recommender = SemanticSearch()
171
 
172
  title = 'PDF GPT'
173
  description = """ PDF GPT allows you to chat with your PDF file using Universal Sentence Encoder and Open AI. It gives hallucination free response than other tools as the embeddings are better than OpenAI. The returned response can even cite the page number in square brackets([]) where the information is located, adding credibility to the responses and helping to locate pertinent information quickly."""
174
- history = []
175
 
176
  with gr.Blocks() as demo:
177
 
@@ -192,12 +183,7 @@ with gr.Blocks() as demo:
192
 
193
  with gr.Group():
194
  answer = gr.Textbox(label='The answer to your question is :')
195
- #history_box = gr.Textbox(label='History of Questions and Answers', value='', type='output', lines=10)
196
- #history_box = gr.Textbox(label='History of Questions and Answers', value='', output=True, lines=10)
197
- #history_box = gr.Textbox(label='History of Questions and Answers', value='', lines=10)
198
- history_box = gr.Textbox(label='History of Questions and Answers', value='', type='text', lines=10)
199
- #btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
200
- btn.click(question_answer, inputs=[url, file, question,openAI_key, history], outputs=[answer, history_box])
201
  #openai.api_key = os.getenv('Your_Key_Here')
202
  demo.launch()
203
-
 
7
  import gradio as gr
8
  import os
9
  from sklearn.neighbors import NearestNeighbors
 
 
 
 
10
 
11
  def download_pdf(url, output_path):
12
  urllib.request.urlretrieve(url, output_path)
 
132
  return answer
133
 
134
 
135
+ def question_answer(url, file, question,openAI_key):
136
+ if openAI_key.strip()=='':
137
+ return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
138
+ if url.strip() == '' and file == None:
139
+ return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
140
+
141
+ if url.strip() != '' and file != None:
142
+ return '[ERROR]: Both URL and PDF is provided. Please provide only one (eiter URL or PDF).'
 
143
 
144
  if url.strip() != '':
145
  glob_url = url
 
156
  if question.strip() == '':
157
  return '[ERROR]: Question field is empty'
158
 
159
+ return generate_answer(question,openAI_key)
 
 
 
160
 
161
 
162
  recommender = SemanticSearch()
163
 
164
  title = 'PDF GPT'
165
  description = """ PDF GPT allows you to chat with your PDF file using Universal Sentence Encoder and Open AI. It gives hallucination free response than other tools as the embeddings are better than OpenAI. The returned response can even cite the page number in square brackets([]) where the information is located, adding credibility to the responses and helping to locate pertinent information quickly."""
 
166
 
167
  with gr.Blocks() as demo:
168
 
 
183
 
184
  with gr.Group():
185
  answer = gr.Textbox(label='The answer to your question is :')
186
+
187
+ btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
 
 
 
 
188
  #openai.api_key = os.getenv('Your_Key_Here')
189
  demo.launch()