Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -127,34 +127,18 @@ def generate_answer(question,openAI_key):
|
|
127 |
prompt += f"Query: {question}\nAnswer:"
|
128 |
answer = generate_text(openAI_key, prompt,"text-davinci-003")
|
129 |
return answer
|
130 |
-
|
131 |
-
|
132 |
-
def question_answer(url, file, question,openAI_key):
|
133 |
-
if openAI_key.strip()=='':
|
134 |
-
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
135 |
-
if url.strip() == '' and file == None:
|
136 |
-
return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
|
137 |
|
138 |
-
|
139 |
-
|
|
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
download_pdf(glob_url, 'corpus.pdf')
|
144 |
-
load_recommender('corpus.pdf')
|
145 |
-
|
146 |
-
else:
|
147 |
-
old_file_name = file.name
|
148 |
-
file_name = file.name
|
149 |
-
file_name = file_name[:-12] + file_name[-4:]
|
150 |
-
os.rename(old_file_name, file_name)
|
151 |
-
load_recommender(file_name)
|
152 |
|
153 |
if question.strip() == '':
|
154 |
return '[ERROR]: Question field is empty'
|
155 |
|
156 |
-
return generate_answer(question
|
157 |
-
|
158 |
|
159 |
recommender = SemanticSearch()
|
160 |
|
@@ -162,18 +146,11 @@ title = 'PDF GPT'
|
|
162 |
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."""
|
163 |
|
164 |
with gr.Blocks() as demo:
|
165 |
-
|
166 |
gr.Markdown(f'<center><h1>{title}</h1></center>')
|
167 |
gr.Markdown(description)
|
168 |
|
169 |
with gr.Row():
|
170 |
-
|
171 |
with gr.Group():
|
172 |
-
gr.Markdown(f'<p style="text-align:center">Get your Open AI API key <a href="https://platform.openai.com/account/api-keys">here</a></p>')
|
173 |
-
openAI_key=gr.Textbox(label='Enter your OpenAI API key here')
|
174 |
-
url = gr.Textbox(label='Enter PDF URL here')
|
175 |
-
gr.Markdown("<center><h4>OR<h4></center>")
|
176 |
-
file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
|
177 |
question = gr.Textbox(label='Enter your question here')
|
178 |
btn = gr.Button(value='Submit')
|
179 |
btn.style(full_width=True)
|
@@ -181,6 +158,6 @@ with gr.Blocks() as demo:
|
|
181 |
with gr.Group():
|
182 |
answer = gr.Textbox(label='The answer to your question is :')
|
183 |
|
184 |
-
btn.click(question_answer, inputs=[
|
185 |
-
|
186 |
demo.launch()
|
|
|
127 |
prompt += f"Query: {question}\nAnswer:"
|
128 |
answer = generate_text(openAI_key, prompt,"text-davinci-003")
|
129 |
return answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
+
def question_answer(url, question):
|
132 |
+
if url.strip() == '':
|
133 |
+
return '[ERROR]: URL is empty. Provide a valid URL.'
|
134 |
|
135 |
+
download_pdf(url, 'corpus.pdf')
|
136 |
+
load_recommender('corpus.pdf')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
if question.strip() == '':
|
139 |
return '[ERROR]: Question field is empty'
|
140 |
|
141 |
+
return generate_answer(question)
|
|
|
142 |
|
143 |
recommender = SemanticSearch()
|
144 |
|
|
|
146 |
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."""
|
147 |
|
148 |
with gr.Blocks() as demo:
|
|
|
149 |
gr.Markdown(f'<center><h1>{title}</h1></center>')
|
150 |
gr.Markdown(description)
|
151 |
|
152 |
with gr.Row():
|
|
|
153 |
with gr.Group():
|
|
|
|
|
|
|
|
|
|
|
154 |
question = gr.Textbox(label='Enter your question here')
|
155 |
btn = gr.Button(value='Submit')
|
156 |
btn.style(full_width=True)
|
|
|
158 |
with gr.Group():
|
159 |
answer = gr.Textbox(label='The answer to your question is :')
|
160 |
|
161 |
+
btn.click(question_answer, inputs=[PDF_URL, question], outputs=[answer])
|
162 |
+
|
163 |
demo.launch()
|