Spaces:
Running
Running
bhaskartripathi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -280,18 +280,19 @@ with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as dem
|
|
280 |
)
|
281 |
|
282 |
def respond(message, chat_history, url_value, file_value, key_value, model_value):
|
|
|
|
|
|
|
283 |
try:
|
284 |
if key_value.strip() == '':
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
]
|
289 |
|
290 |
if url_value.strip() == '' and file_value is None:
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
]
|
295 |
|
296 |
# Process PDF and generate answer
|
297 |
if url_value.strip() != '':
|
@@ -305,16 +306,15 @@ with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as dem
|
|
305 |
|
306 |
answer = generate_answer(message, key_value, model_value)
|
307 |
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
|
313 |
except Exception as e:
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
]
|
318 |
|
319 |
submit_btn.click(
|
320 |
respond,
|
@@ -328,4 +328,6 @@ with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as dem
|
|
328 |
[msg, chatbot]
|
329 |
)
|
330 |
|
331 |
-
demo.launch()
|
|
|
|
|
|
280 |
)
|
281 |
|
282 |
def respond(message, chat_history, url_value, file_value, key_value, model_value):
|
283 |
+
if message.strip() == "":
|
284 |
+
return "", chat_history # Return empty message if no input
|
285 |
+
|
286 |
try:
|
287 |
if key_value.strip() == '':
|
288 |
+
chat_history.append({"role": "user", "content": message})
|
289 |
+
chat_history.append({"role": "assistant", "content": '[ERROR]: Please enter your OpenAI API key'})
|
290 |
+
return "", chat_history
|
|
|
291 |
|
292 |
if url_value.strip() == '' and file_value is None:
|
293 |
+
chat_history.append({"role": "user", "content": message})
|
294 |
+
chat_history.append({"role": "assistant", "content": '[ERROR]: Both URL and PDF are empty. Provide at least one'})
|
295 |
+
return "", chat_history
|
|
|
296 |
|
297 |
# Process PDF and generate answer
|
298 |
if url_value.strip() != '':
|
|
|
306 |
|
307 |
answer = generate_answer(message, key_value, model_value)
|
308 |
|
309 |
+
chat_history.append({"role": "user", "content": message})
|
310 |
+
chat_history.append({"role": "assistant", "content": answer})
|
311 |
+
|
312 |
+
return "", chat_history
|
313 |
|
314 |
except Exception as e:
|
315 |
+
chat_history.append({"role": "user", "content": message})
|
316 |
+
chat_history.append({"role": "assistant", "content": f'[ERROR]: {str(e)}'})
|
317 |
+
return "", chat_history
|
|
|
318 |
|
319 |
submit_btn.click(
|
320 |
respond,
|
|
|
328 |
[msg, chatbot]
|
329 |
)
|
330 |
|
331 |
+
demo.launch()
|
332 |
+
|
333 |
+
|