Spaces:
Runtime error
Runtime error
Commit
·
18867be
1
Parent(s):
b1491dd
Update app.py
Browse files
app.py
CHANGED
|
@@ -141,7 +141,7 @@ def generate_answer(question, openAI_key,model):
|
|
| 141 |
answer = generate_text(openAI_key, prompt, model)
|
| 142 |
return answer
|
| 143 |
|
| 144 |
-
def
|
| 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'
|
|
@@ -170,42 +170,6 @@ def question_answer1(url, file, 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 |
-
def question_answer(url, file, question, openAI_key, model):
|
| 174 |
-
try:
|
| 175 |
-
if openAI_key.strip()=='':
|
| 176 |
-
return ['[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys']
|
| 177 |
-
if url.strip() == '' and file == None:
|
| 178 |
-
return ['[ERROR]: Both URL and PDF is empty. Provide at least one.']
|
| 179 |
-
if url.strip() != '' and file != None:
|
| 180 |
-
return ['[ERROR]: Both URL and PDF is provided. Please provide only one (either URL or PDF).']
|
| 181 |
-
if model is None or model =='':
|
| 182 |
-
return ['[ERROR]: You have not selected any model. Please choose an LLM model.']
|
| 183 |
-
if url.strip() != '':
|
| 184 |
-
glob_url = url
|
| 185 |
-
download_pdf(glob_url, 'corpus.pdf')
|
| 186 |
-
load_recommender('corpus.pdf')
|
| 187 |
-
else:
|
| 188 |
-
old_file_name = file.name
|
| 189 |
-
file_name = file.name
|
| 190 |
-
file_name = file_name[:-12] + file_name[-4:]
|
| 191 |
-
os.rename(old_file_name, file_name)
|
| 192 |
-
load_recommender(file_name)
|
| 193 |
-
if question.strip() == '':
|
| 194 |
-
return ['[ERROR]: Question field is empty']
|
| 195 |
-
if model == "text-davinci-003":
|
| 196 |
-
answer = generate_answer_text_davinci_003(question, openAI_key)
|
| 197 |
-
else:
|
| 198 |
-
answer = generate_answer(question, openAI_key, model)
|
| 199 |
-
return [{USER_NAME: question, BOT_NAME: answer}]
|
| 200 |
-
except openai.error.InvalidRequestError as e:
|
| 201 |
-
return [{USER_NAME: question, '[ERROR]': 'Either you do not have access to GPT4 or you have exhausted your quota!'}]
|
| 202 |
-
|
| 203 |
-
# define gr.Chatbox for answer
|
| 204 |
-
answer = gr.Chatbot(label='The answer to your question is :', placeholder='Type your question and press enter')
|
| 205 |
-
|
| 206 |
-
# define gr.Chatbox for question
|
| 207 |
-
question = gr.Chatbot(placeholder='Enter your question here', label='Enter your question here', message_pairs=[['User', '']])
|
| 208 |
-
|
| 209 |
|
| 210 |
|
| 211 |
def generate_text_text_davinci_003(openAI_key,prompt, engine="text-davinci-003"):
|
|
@@ -294,9 +258,6 @@ with gr.Blocks() as demo:
|
|
| 294 |
|
| 295 |
|
| 296 |
#btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
|
| 297 |
-
#btn.click(question_answer, inputs=[url, file, question, openAI_key, model], outputs=[answer])
|
| 298 |
btn.click(question_answer, inputs=[url, file, question, openAI_key, model], outputs=[answer])
|
| 299 |
-
|
| 300 |
#openai.api_key = os.getenv('Your_Key_Here')
|
| 301 |
demo.launch()
|
| 302 |
-
|
|
|
|
| 141 |
answer = generate_text(openAI_key, prompt, model)
|
| 142 |
return answer
|
| 143 |
|
| 144 |
+
def question_answer(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'
|
|
|
|
| 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 |
|
| 174 |
|
| 175 |
def generate_text_text_davinci_003(openAI_key,prompt, engine="text-davinci-003"):
|
|
|
|
| 258 |
|
| 259 |
|
| 260 |
#btn.click(question_answer, inputs=[url, file, question,openAI_key], outputs=[answer])
|
|
|
|
| 261 |
btn.click(question_answer, inputs=[url, file, question, openAI_key, model], outputs=[answer])
|
|
|
|
| 262 |
#openai.api_key = os.getenv('Your_Key_Here')
|
| 263 |
demo.launch()
|
|
|