Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -239,48 +239,6 @@ recommender = SemanticSearch()
|
|
| 239 |
title = 'PDF GPT Turbo'
|
| 240 |
description = """ PDF GPT Turbo allows you to chat with your PDF files. It uses Google's Universal Sentence Encoder with Deep averaging network (DAN) to give hallucination free response by improving the embedding quality of OpenAI. It cites the page number in square brackets([Page No.]) and shows where the information is located, adding credibility to the responses."""
|
| 241 |
|
| 242 |
-
#with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as demo:
|
| 243 |
-
with gr.Blocks() as demo:
|
| 244 |
-
gr.Markdown(f'<center><h3>{title}</h3></center>')
|
| 245 |
-
gr.Markdown(description)
|
| 246 |
-
|
| 247 |
-
with gr.Row():
|
| 248 |
-
with gr.Column():
|
| 249 |
-
# API Key and File Inputs
|
| 250 |
-
with gr.Accordion("API Key and PDF"):
|
| 251 |
-
openAI_key = gr.Textbox(label='Enter your OpenAI API key here', type='password')
|
| 252 |
-
url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf ; https://link.springer.com/content/pdf/10.1007/s10614-022-10325-8.pdf)')
|
| 253 |
-
gr.Markdown("<center><h4>OR<h4></center>")
|
| 254 |
-
file = gr.File(label='Upload your PDF/Research Paper/Book here', file_types=['.pdf'])
|
| 255 |
-
|
| 256 |
-
# Model Selection
|
| 257 |
-
model = gr.Radio(
|
| 258 |
-
choices=[
|
| 259 |
-
'gpt-4o-mini',
|
| 260 |
-
'gpt-4o',
|
| 261 |
-
'gpt-4',
|
| 262 |
-
],
|
| 263 |
-
label='Select Model',
|
| 264 |
-
value='gpt-4o-mini'
|
| 265 |
-
)
|
| 266 |
-
|
| 267 |
-
# Chat Interface
|
| 268 |
-
chatbot = gr.Chatbot(label="Chat History") # default: list of [user, bot] pairs
|
| 269 |
-
msg = gr.Textbox(label="Enter your question here", lines=2)
|
| 270 |
-
submit_btn = gr.Button("Submit")
|
| 271 |
-
clear = gr.ClearButton([msg, chatbot])
|
| 272 |
-
#chatbot = gr.Chatbot(label="Chat History", type="messages")
|
| 273 |
-
#msg = gr.Textbox(label="Enter your question here", lines=2)
|
| 274 |
-
#submit_btn = gr.Button("Submit")
|
| 275 |
-
#clear = gr.ClearButton([msg, chatbot])
|
| 276 |
-
|
| 277 |
-
# Example Questions
|
| 278 |
-
gr.Examples(
|
| 279 |
-
[[q] for q in questions],
|
| 280 |
-
inputs=[msg],
|
| 281 |
-
label="PRE-DEFINED QUESTIONS: Click on a question to auto-fill the input box",
|
| 282 |
-
)
|
| 283 |
-
|
| 284 |
def respond(message, chat_history, url_value, file_value, key_value, model_value):
|
| 285 |
if message.strip() == "":
|
| 286 |
return "", chat_history # nothing to do
|
|
@@ -320,16 +278,106 @@ def respond(message, chat_history, url_value, file_value, key_value, model_value
|
|
| 320 |
chat_history.append([message, f'[ERROR]: {str(e)}'])
|
| 321 |
return "", chat_history
|
| 322 |
|
| 323 |
-
submit_btn.click(
|
| 324 |
-
respond,
|
| 325 |
-
[msg, chatbot, url, file, openAI_key, model],
|
| 326 |
-
[msg, chatbot]
|
| 327 |
-
)
|
| 328 |
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
)
|
| 334 |
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
title = 'PDF GPT Turbo'
|
| 240 |
description = """ PDF GPT Turbo allows you to chat with your PDF files. It uses Google's Universal Sentence Encoder with Deep averaging network (DAN) to give hallucination free response by improving the embedding quality of OpenAI. It cites the page number in square brackets([Page No.]) and shows where the information is located, adding credibility to the responses."""
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
def respond(message, chat_history, url_value, file_value, key_value, model_value):
|
| 243 |
if message.strip() == "":
|
| 244 |
return "", chat_history # nothing to do
|
|
|
|
| 278 |
chat_history.append([message, f'[ERROR]: {str(e)}'])
|
| 279 |
return "", chat_history
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
+
with gr.Blocks() as demo:
|
| 283 |
+
gr.Markdown(f'<center><h3>{title}</h3></center>')
|
| 284 |
+
gr.Markdown(description)
|
| 285 |
+
|
| 286 |
+
with gr.Row():
|
| 287 |
+
with gr.Column():
|
| 288 |
+
with gr.Accordion("API Key and PDF"):
|
| 289 |
+
openAI_key = gr.Textbox(label='Enter your OpenAI API key here', type='password')
|
| 290 |
+
url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf ; https://link.springer.com/content/pdf/10.1007/s10614-022-10325-8.pdf)')
|
| 291 |
+
gr.Markdown("<center><h4>OR<h4></center>")
|
| 292 |
+
file = gr.File(label='Upload your PDF/Research Paper/Book here', file_types=['.pdf'])
|
| 293 |
+
|
| 294 |
+
model = gr.Radio(
|
| 295 |
+
choices=['gpt-4o-mini', 'gpt-4o', 'gpt-4'],
|
| 296 |
+
label='Select Model',
|
| 297 |
+
value='gpt-4o-mini'
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
chatbot = gr.Chatbot(label="Chat History")
|
| 301 |
+
msg = gr.Textbox(label="Enter your question here", lines=2)
|
| 302 |
+
submit_btn = gr.Button("Submit")
|
| 303 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 304 |
+
|
| 305 |
+
gr.Examples(
|
| 306 |
+
[[q] for q in questions],
|
| 307 |
+
inputs=[msg],
|
| 308 |
+
label="PRE-DEFINED QUESTIONS: Click on a question to auto-fill the input box",
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
# 🔗 Wire events HERE, still inside `with gr.Blocks()`
|
| 312 |
+
submit_btn.click(
|
| 313 |
+
respond,
|
| 314 |
+
[msg, chatbot, url, file, openAI_key, model],
|
| 315 |
+
[msg, chatbot],
|
| 316 |
)
|
| 317 |
|
| 318 |
+
msg.submit(
|
| 319 |
+
respond,
|
| 320 |
+
[msg, chatbot, url, file, openAI_key, model],
|
| 321 |
+
[msg, chatbot],
|
| 322 |
+
)
|
| 323 |
+
|
| 324 |
+
demo.launch()
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
# #with gr.Blocks(css="""#chatbot { font-size: 14px; min-height: 1200; }""") as demo:
|
| 328 |
+
# with gr.Blocks() as demo:
|
| 329 |
+
# gr.Markdown(f'<center><h3>{title}</h3></center>')
|
| 330 |
+
# gr.Markdown(description)
|
| 331 |
+
|
| 332 |
+
# with gr.Row():
|
| 333 |
+
# with gr.Column():
|
| 334 |
+
# # API Key and File Inputs
|
| 335 |
+
# with gr.Accordion("API Key and PDF"):
|
| 336 |
+
# openAI_key = gr.Textbox(label='Enter your OpenAI API key here', type='password')
|
| 337 |
+
# url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf ; https://link.springer.com/content/pdf/10.1007/s10614-022-10325-8.pdf)')
|
| 338 |
+
# gr.Markdown("<center><h4>OR<h4></center>")
|
| 339 |
+
# file = gr.File(label='Upload your PDF/Research Paper/Book here', file_types=['.pdf'])
|
| 340 |
+
|
| 341 |
+
# # Model Selection
|
| 342 |
+
# model = gr.Radio(
|
| 343 |
+
# choices=[
|
| 344 |
+
# 'gpt-4o-mini',
|
| 345 |
+
# 'gpt-4o',
|
| 346 |
+
# 'gpt-4',
|
| 347 |
+
# ],
|
| 348 |
+
# label='Select Model',
|
| 349 |
+
# value='gpt-4o-mini'
|
| 350 |
+
# )
|
| 351 |
+
|
| 352 |
+
# # Chat Interface
|
| 353 |
+
# chatbot = gr.Chatbot(label="Chat History") # default: list of [user, bot] pairs
|
| 354 |
+
# msg = gr.Textbox(label="Enter your question here", lines=2)
|
| 355 |
+
# submit_btn = gr.Button("Submit")
|
| 356 |
+
# clear = gr.ClearButton([msg, chatbot])
|
| 357 |
+
# #chatbot = gr.Chatbot(label="Chat History", type="messages")
|
| 358 |
+
# #msg = gr.Textbox(label="Enter your question here", lines=2)
|
| 359 |
+
# #submit_btn = gr.Button("Submit")
|
| 360 |
+
# #clear = gr.ClearButton([msg, chatbot])
|
| 361 |
+
|
| 362 |
+
# # Example Questions
|
| 363 |
+
# gr.Examples(
|
| 364 |
+
# [[q] for q in questions],
|
| 365 |
+
# inputs=[msg],
|
| 366 |
+
# label="PRE-DEFINED QUESTIONS: Click on a question to auto-fill the input box",
|
| 367 |
+
# )
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
# submit_btn.click(
|
| 372 |
+
# respond,
|
| 373 |
+
# [msg, chatbot, url, file, openAI_key, model],
|
| 374 |
+
# [msg, chatbot]
|
| 375 |
+
# )
|
| 376 |
+
|
| 377 |
+
# msg.submit(
|
| 378 |
+
# respond,
|
| 379 |
+
# [msg, chatbot, url, file, openAI_key, model],
|
| 380 |
+
# [msg, chatbot]
|
| 381 |
+
# )
|
| 382 |
+
|
| 383 |
+
# demo.launch()
|