Spaces:
Runtime error
Runtime error
Commit
·
cda9639
1
Parent(s):
976f7c9
Update app.py
Browse files
app.py
CHANGED
|
@@ -168,31 +168,31 @@ def generate_answer(question,openAI_key):
|
|
| 168 |
return answer
|
| 169 |
|
| 170 |
|
| 171 |
-
def question_answer(url, file, question,openAI_key):
|
| 172 |
-
if openAI_key.strip()=='':
|
| 173 |
-
return '[ERROR]: Please enter
|
| 174 |
if url.strip() == '' and file == None:
|
| 175 |
-
return '[ERROR]: Both URL and PDF is empty. Provide
|
| 176 |
|
| 177 |
if url.strip() != '' and file != None:
|
| 178 |
-
return '[ERROR]: Both URL and PDF is provided. Please provide only one (
|
| 179 |
|
| 180 |
if url.strip() != '':
|
| 181 |
glob_url = url
|
| 182 |
download_pdf(glob_url, 'corpus.pdf')
|
| 183 |
-
load_recommender('corpus.pdf')
|
| 184 |
|
| 185 |
else:
|
| 186 |
old_file_name = file.name
|
| 187 |
file_name = file.name
|
| 188 |
file_name = file_name[:-12] + file_name[-4:]
|
| 189 |
os.rename(old_file_name, file_name)
|
| 190 |
-
load_recommender(file_name)
|
| 191 |
|
| 192 |
if question.strip() == '':
|
| 193 |
return '[ERROR]: Question field is empty'
|
| 194 |
|
| 195 |
-
return generate_answer(question,openAI_key)
|
| 196 |
|
| 197 |
|
| 198 |
recommender = SemanticSearch()
|
|
@@ -223,5 +223,25 @@ with gr.Blocks() as demo:
|
|
| 223 |
answer = gr.Textbox(label='The answer to your question is :')
|
| 224 |
|
| 225 |
btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
#openai.api_key = os.getenv('Your_Key_Here')
|
| 227 |
demo.launch()
|
|
|
|
| 168 |
return answer
|
| 169 |
|
| 170 |
|
| 171 |
+
def question_answer(url, file, question, openAI_key, start_page, end_page):
|
| 172 |
+
if openAI_key.strip() == '':
|
| 173 |
+
return '[ERROR]: Please enter your Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
| 174 |
if url.strip() == '' and file == None:
|
| 175 |
+
return '[ERROR]: Both URL and PDF is empty. Provide at least one.'
|
| 176 |
|
| 177 |
if url.strip() != '' and file != None:
|
| 178 |
+
return '[ERROR]: Both URL and PDF is provided. Please provide only one (either URL or PDF).'
|
| 179 |
|
| 180 |
if url.strip() != '':
|
| 181 |
glob_url = url
|
| 182 |
download_pdf(glob_url, 'corpus.pdf')
|
| 183 |
+
load_recommender('corpus.pdf', start_page=start_page, end_page=end_page)
|
| 184 |
|
| 185 |
else:
|
| 186 |
old_file_name = file.name
|
| 187 |
file_name = file.name
|
| 188 |
file_name = file_name[:-12] + file_name[-4:]
|
| 189 |
os.rename(old_file_name, file_name)
|
| 190 |
+
load_recommender(file_name, start_page=start_page, end_page=end_page)
|
| 191 |
|
| 192 |
if question.strip() == '':
|
| 193 |
return '[ERROR]: Question field is empty'
|
| 194 |
|
| 195 |
+
return generate_answer(question, openAI_key)
|
| 196 |
|
| 197 |
|
| 198 |
recommender = SemanticSearch()
|
|
|
|
| 223 |
answer = gr.Textbox(label='The answer to your question is :')
|
| 224 |
|
| 225 |
btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
|
| 226 |
+
with gr.Row():
|
| 227 |
+
|
| 228 |
+
with gr.Group():
|
| 229 |
+
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>')
|
| 230 |
+
openAI_key = gr.Textbox(label='Enter your OpenAI API key here')
|
| 231 |
+
url = gr.Textbox(label='Enter PDF URL here')
|
| 232 |
+
gr.Markdown("<center><h4>OR<h4></center>")
|
| 233 |
+
file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
|
| 234 |
+
question = gr.Textbox(label='Enter your question here')
|
| 235 |
+
start_page = gr.Textbox(label='Start on page (optional):', numeric=True)
|
| 236 |
+
end_page = gr.Textbox(label='End on page (optional):', numeric=True)
|
| 237 |
+
btn = gr.Button(value='Submit')
|
| 238 |
+
btn.style(full_width=True)
|
| 239 |
+
|
| 240 |
+
with gr.Group():
|
| 241 |
+
answer = gr.Textbox(label='The answer to your question is :')
|
| 242 |
+
|
| 243 |
+
btn.click(question_answer, inputs=[url, file, question, openAI_key, start_page, end_page], outputs=[answer])
|
| 244 |
+
|
| 245 |
+
|
| 246 |
#openai.api_key = os.getenv('Your_Key_Here')
|
| 247 |
demo.launch()
|