Spaces:
Runtime error
Runtime error
Commit
·
72ca0f0
1
Parent(s):
105f709
Update app.py
Browse files
app.py
CHANGED
|
@@ -175,10 +175,10 @@ def question_answer1(url, file, question, openAI_key, model):
|
|
| 175 |
def question_answer(chat_history, url, file, question, openAI_key, model):
|
| 176 |
try:
|
| 177 |
if openAI_key.strip()=='':
|
| 178 |
-
return '[ERROR]: Please enter your
|
| 179 |
-
if url.strip() == '' and file
|
| 180 |
return '[ERROR]: Both URL and PDF is empty. Provide at least one.'
|
| 181 |
-
if url.strip() != '' and file
|
| 182 |
return '[ERROR]: Both URL and PDF is provided. Please provide only one (either URL or PDF).'
|
| 183 |
if model is None or model =='':
|
| 184 |
return '[ERROR]: You have not selected any model. Please choose an LLM model.'
|
|
@@ -195,15 +195,16 @@ def question_answer(chat_history, url, file, question, openAI_key, model):
|
|
| 195 |
if question.strip() == '':
|
| 196 |
return '[ERROR]: Question field is empty'
|
| 197 |
if model == "text-davinci-003":
|
| 198 |
-
|
| 199 |
else:
|
| 200 |
answer = generate_answer(question, openAI_key, model)
|
| 201 |
-
|
| 202 |
-
|
| 203 |
except openai.error.InvalidRequestError as e:
|
| 204 |
return f'[ERROR]: Either you do not have access to GPT4 or you have exhausted your quota!'
|
| 205 |
|
| 206 |
|
|
|
|
| 207 |
def generate_text_text_davinci_003(openAI_key,prompt, engine="text-davinci-003"):
|
| 208 |
openai.api_key = openAI_key
|
| 209 |
completions = openai.Completion.create(
|
|
@@ -284,11 +285,11 @@ with gr.Blocks() as demo:
|
|
| 284 |
with gr.Group():
|
| 285 |
chatbot = gr.Chatbot(placeholder="Chat History", label="Chat History", lines=20)
|
| 286 |
|
| 287 |
-
|
|
|
|
| 288 |
question_answer,
|
| 289 |
-
[chatbot, url, file, question, openAI_key, model],
|
| 290 |
outputs=[chatbot],
|
| 291 |
-
show_progress=False,
|
| 292 |
)
|
| 293 |
|
| 294 |
#openai.api_key = os.getenv('Your_Key_Here')
|
|
|
|
| 175 |
def question_answer(chat_history, url, file, question, openAI_key, model):
|
| 176 |
try:
|
| 177 |
if openAI_key.strip()=='':
|
| 178 |
+
return '[ERROR]: Please enter your Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
|
| 179 |
+
if url.strip() == '' and file is None:
|
| 180 |
return '[ERROR]: Both URL and PDF is empty. Provide at least one.'
|
| 181 |
+
if url.strip() != '' and file is not None:
|
| 182 |
return '[ERROR]: Both URL and PDF is provided. Please provide only one (either URL or PDF).'
|
| 183 |
if model is None or model =='':
|
| 184 |
return '[ERROR]: You have not selected any model. Please choose an LLM model.'
|
|
|
|
| 195 |
if question.strip() == '':
|
| 196 |
return '[ERROR]: Question field is empty'
|
| 197 |
if model == "text-davinci-003":
|
| 198 |
+
answer = generate_answer_text_davinci_003(question, openAI_key)
|
| 199 |
else:
|
| 200 |
answer = generate_answer(question, openAI_key, model)
|
| 201 |
+
chat_history.append([question, answer])
|
| 202 |
+
return chat_history
|
| 203 |
except openai.error.InvalidRequestError as e:
|
| 204 |
return f'[ERROR]: Either you do not have access to GPT4 or you have exhausted your quota!'
|
| 205 |
|
| 206 |
|
| 207 |
+
|
| 208 |
def generate_text_text_davinci_003(openAI_key,prompt, engine="text-davinci-003"):
|
| 209 |
openai.api_key = openAI_key
|
| 210 |
completions = openai.Completion.create(
|
|
|
|
| 285 |
with gr.Group():
|
| 286 |
chatbot = gr.Chatbot(placeholder="Chat History", label="Chat History", lines=20)
|
| 287 |
|
| 288 |
+
# Bind the click event of the button to the question_answer function
|
| 289 |
+
btn.click(
|
| 290 |
question_answer,
|
| 291 |
+
inputs=[chatbot, url, file, question, openAI_key, model],
|
| 292 |
outputs=[chatbot],
|
|
|
|
| 293 |
)
|
| 294 |
|
| 295 |
#openai.api_key = os.getenv('Your_Key_Here')
|