Kexin2000 commited on
Commit
0d33c91
1 Parent(s): dc79649

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -24
app.py CHANGED
@@ -366,34 +366,58 @@ description_2 = (
366
  "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."
367
  )
368
 
369
- # 创建第一个界面
370
- interface_1 = gr.Interface(
 
371
  return_recommendations,
372
  gr.Textbox(lines=1),
373
  gr.Markdown(),
374
  examples=examples_1,
375
- title=title_1,
376
- description=description_1,
377
  )
378
 
379
- interface_2 = gr.Interface(
380
- fn=question_answer,
381
- inputs=[
382
- gr.Chatbot(),
383
- gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf )'),
384
- gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf']),
385
- gr.Textbox(label='Enter your question here'),
386
- gr.Textbox(label='Enter your OpenAI API key here'),
387
- gr.Radio(['gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-16k-0613', 'text-davinci-003', 'gpt-4', 'gpt-4-32k'], label='Select Model'),
388
- ],
389
- outputs=[gr.Chatbot()],
390
- examples=[],
391
- title=title_2,
392
- description=description_2,
393
- )
394
-
395
- # 启动第一个界面
396
- interface_1.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
 
398
- # 启动第二个界面
399
- interface_2.launch()
 
 
366
  "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."
367
  )
368
 
369
+ with gr.Tab(title=title_1) as tab1:
370
+ gr.Markdown(description_1)
371
+ interface = gr.Interface(
372
  return_recommendations,
373
  gr.Textbox(lines=1),
374
  gr.Markdown(),
375
  examples=examples_1,
376
+ title=title,
377
+ description=description,
378
  )
379
 
380
+ with gr.Tab(title=title2) as tab2:
381
+ gr.Markdown(f'<center><h3>{title_2}</h3></center>')
382
+ gr.Markdown(description_2)
383
+ with gr.Row():
384
+ with gr.Group():
385
+ gr.Markdown(f'<p style="text-align:center">Get your Open AI API key <a href="https://platform.openai.com/account/api-keys">here</a></p>')
386
+ with gr.Accordion("API Key"):
387
+ openAI_key = gr.Textbox(label='Enter your OpenAI API key here', password=True)
388
+ url = gr.Textbox(label='Enter PDF URL here (Example: https://arxiv.org/pdf/1706.03762.pdf )')
389
+ gr.Markdown("<center><h4>OR<h4></center>")
390
+ file = gr.File(label='Upload your PDF/ Research Paper / Book here', file_types=['.pdf'])
391
+ question = gr.Textbox(label='Enter your question here')
392
+ gr.Examples(
393
+ [[q] for q in questions],
394
+ inputs=[question],
395
+ label="PRE-DEFINED QUESTIONS: Click on a question to auto-fill the input box, then press Enter!",
396
+ )
397
+ model = gr.Radio([
398
+ 'gpt-3.5-turbo',
399
+ 'gpt-3.5-turbo-16k',
400
+ 'gpt-3.5-turbo-0613',
401
+ 'gpt-3.5-turbo-16k-0613',
402
+ 'text-davinci-003',
403
+ 'gpt-4',
404
+ 'gpt-4-32k'
405
+ ], label='Select Model', default='gpt-3.5-turbo')
406
+ btn = gr.Button(value='Submit')
407
+
408
+ btn.style(full_width=True)
409
+
410
+ with gr.Group():
411
+ chatbot = gr.Chatbot(placeholder="Chat History", label="Chat History", lines=50, elem_id="chatbot")
412
+
413
+
414
+ # Bind the click event of the button to the question_answer function
415
+ btn.click(
416
+ question_answer,
417
+ inputs=[chatbot, url, file, question, openAI_key, model],
418
+ outputs=[chatbot],
419
+ )
420
 
421
+ # 将两个界面放入一个 Tab 应用中
422
+ demo = gr.TabbedInterface([tab1, tab2], ["Tab 1", "Tab 2"])
423
+ demo.launch()