bhaskartripathi commited on
Commit
54e37e6
1 Parent(s): f82b5ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
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 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,9 +146,6 @@ def question_answer(url, file, question, openAI_key):
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,7 +155,7 @@ def question_answer(url, file, question, openAI_key):
158
  if question.strip() == '':
159
  return '[ERROR]: Question field is empty'
160
 
161
- return generate_answer(question, openAI_key)
162
 
163
 
164
  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 you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
137
+ if url.strip() == '' and file == None:
138
+ return '[ERROR]: Both URL and PDF is empty. Provide atleast one.'
139
+
140
+ if url.strip() != '' and file != None:
141
+ return '[ERROR]: Both URL and PDF is provided. Please provide only one (eiter URL or PDF).'
142
 
143
  if url.strip() != '':
144
  glob_url = url
 
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
  if question.strip() == '':
156
  return '[ERROR]: Question field is empty'
157
 
158
+ return generate_answer(question,openAI_key)
159
 
160
 
161
  recommender = SemanticSearch()