Spaces:
Running
Running
Commit
·
f82b5ba
1
Parent(s):
877302b
Update app.py
Browse files
app.py
CHANGED
|
@@ -131,14 +131,14 @@ def generate_answer(question,openAI_key):
|
|
| 131 |
return answer
|
| 132 |
|
| 133 |
|
| 134 |
-
def question_answer(url, file, question,openAI_key):
|
| 135 |
-
if openAI_key.strip()=='':
|
| 136 |
-
return '[ERROR]: Please enter
|
| 137 |
-
if url.strip() == '' and file ==
|
| 138 |
-
return '[ERROR]: Both URL and PDF is empty. Provide
|
| 139 |
-
|
| 140 |
-
if url.strip() != '' and file !=
|
| 141 |
-
return '[ERROR]: Both URL and PDF is provided. Please provide only one (
|
| 142 |
|
| 143 |
if url.strip() != '':
|
| 144 |
glob_url = url
|
|
@@ -146,6 +146,9 @@ def question_answer(url, file, question,openAI_key):
|
|
| 146 |
load_recommender('corpus.pdf')
|
| 147 |
|
| 148 |
else:
|
|
|
|
|
|
|
|
|
|
| 149 |
old_file_name = file.name
|
| 150 |
file_name = file.name
|
| 151 |
file_name = file_name[:-12] + file_name[-4:]
|
|
@@ -155,7 +158,7 @@ def question_answer(url, file, question,openAI_key):
|
|
| 155 |
if question.strip() == '':
|
| 156 |
return '[ERROR]: Question field is empty'
|
| 157 |
|
| 158 |
-
return generate_answer(question,openAI_key)
|
| 159 |
|
| 160 |
|
| 161 |
recommender = SemanticSearch()
|
|
|
|
| 131 |
return answer
|
| 132 |
|
| 133 |
|
| 134 |
+
def question_answer(url, file, question, openAI_key):
|
| 135 |
+
if openAI_key.strip() == '':
|
| 136 |
+
return '[ERROR]: Please enter your Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
| 137 |
+
if url.strip() == '' and (file is None or file.size == 0):
|
| 138 |
+
return '[ERROR]: Both URL and PDF is empty. Provide at least one.'
|
| 139 |
+
|
| 140 |
+
if url.strip() != '' and (file is not None and file.size != 0):
|
| 141 |
+
return '[ERROR]: Both URL and PDF is provided. Please provide only one (either URL or PDF).'
|
| 142 |
|
| 143 |
if url.strip() != '':
|
| 144 |
glob_url = url
|
|
|
|
| 146 |
load_recommender('corpus.pdf')
|
| 147 |
|
| 148 |
else:
|
| 149 |
+
if file.size == 0:
|
| 150 |
+
return '[ERROR]: The uploaded file is empty. Please provide a non-empty PDF file.'
|
| 151 |
+
|
| 152 |
old_file_name = file.name
|
| 153 |
file_name = file.name
|
| 154 |
file_name = file_name[:-12] + file_name[-4:]
|
|
|
|
| 158 |
if question.strip() == '':
|
| 159 |
return '[ERROR]: Question field is empty'
|
| 160 |
|
| 161 |
+
return generate_answer(question, openAI_key)
|
| 162 |
|
| 163 |
|
| 164 |
recommender = SemanticSearch()
|