Spaces:
Runtime error
Runtime error
bhaskartripathi
commited on
Commit
•
6e9602b
1
Parent(s):
b3f0412
Update app.py
Browse files
app.py
CHANGED
@@ -141,37 +141,6 @@ def generate_answer(question, openAI_key,model):
|
|
141 |
answer = generate_text(openAI_key, prompt, model)
|
142 |
return answer
|
143 |
|
144 |
-
def question_answer1(url, file, question, openAI_key, model):
|
145 |
-
try:
|
146 |
-
if openAI_key.strip()=='':
|
147 |
-
return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
148 |
-
if url.strip() == '' and file == None:
|
149 |
-
return '[ERROR]: Both URL and PDF is empty. Provide at least one.'
|
150 |
-
if url.strip() != '' and file != None:
|
151 |
-
return '[ERROR]: Both URL and PDF is provided. Please provide only one (either URL or PDF).'
|
152 |
-
if model is None or model =='':
|
153 |
-
return '[ERROR]: You have not selected any model. Please choose an LLM model.'
|
154 |
-
if url.strip() != '':
|
155 |
-
glob_url = url
|
156 |
-
download_pdf(glob_url, 'corpus.pdf')
|
157 |
-
load_recommender('corpus.pdf')
|
158 |
-
else:
|
159 |
-
old_file_name = file.name
|
160 |
-
file_name = file.name
|
161 |
-
file_name = file_name[:-12] + file_name[-4:]
|
162 |
-
os.rename(old_file_name, file_name)
|
163 |
-
load_recommender(file_name)
|
164 |
-
if question.strip() == '':
|
165 |
-
return '[ERROR]: Question field is empty'
|
166 |
-
if model == "text-davinci-003":
|
167 |
-
return generate_answer_text_davinci_003(question, openAI_key)
|
168 |
-
else:
|
169 |
-
return generate_answer(question, openAI_key, model)
|
170 |
-
except openai.error.InvalidRequestError as e:
|
171 |
-
return f'[ERROR]: Either you do not have access to GPT4 or you have exhausted your quota!'
|
172 |
-
|
173 |
-
# Modifying your code to include chat history feature
|
174 |
-
|
175 |
def question_answer(chat_history, url, file, question, openAI_key, model):
|
176 |
try:
|
177 |
if openAI_key.strip()=='':
|
|
|
141 |
answer = generate_text(openAI_key, prompt, model)
|
142 |
return answer
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
def question_answer(chat_history, url, file, question, openAI_key, model):
|
145 |
try:
|
146 |
if openAI_key.strip()=='':
|