wholewhale commited on
Commit
8d1c8be
1 Parent(s): a41389e

split summary

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -37,20 +37,58 @@ def chat_with_pdf(question):
37
  prompt = ChatPromptTemplate.from_messages([
38
  ("human", pdf_content),
39
  ("human", question),
 
40
  ])
41
 
42
  # Invoke the model using the chain
43
  chain = prompt | model
44
  response = chain.invoke({})
45
-
46
- return response.content
 
 
 
 
 
 
 
47
 
48
  # Define Gradio UI
 
 
 
 
 
 
 
 
 
49
  def gradio_interface(pdf_doc, question):
50
  if not pdf_content:
51
  return load_pdf(pdf_doc)
52
  else:
53
- return chat_with_pdf(question)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  gr.Interface(fn=gradio_interface,
56
  inputs=[gr.File(label="Load a pdf", file_types=['.pdf'], type="file"),
 
37
  prompt = ChatPromptTemplate.from_messages([
38
  ("human", pdf_content),
39
  ("human", question),
40
+ ("human", "Give a clear summary of this pdf information at a 8th grade reading level.")
41
  ])
42
 
43
  # Invoke the model using the chain
44
  chain = prompt | model
45
  response = chain.invoke({})
46
+
47
+ # Get the summary of the PDF content
48
+ summarizer = pipeline("summarization")
49
+ summary = summarizer(pdf_content, max_length=1000, min_length=30, do_sample=False)[0]['summary_text']
50
+
51
+ # Combine the chat response and the summary
52
+ combined_response = f"Summary: {summary}\n\nChat Response: {response.content}"
53
+
54
+ return combined_response
55
 
56
  # Define Gradio UI
57
+ def gradio_interface(pdf_doc, question):
58
+ # ...
59
+ return gr.Interface(
60
+ fn=chat_with_pdf,
61
+ inputs=[pdf_doc, question],
62
+ outputs=gr.outputs.Textbox(),
63
+ api_name='chat_with_pdf_2'
64
+ )
65
+
66
  def gradio_interface(pdf_doc, question):
67
  if not pdf_content:
68
  return load_pdf(pdf_doc)
69
  else:
70
+ # Get the summary of the PDF content
71
+ summarizer = pipeline("summarization")
72
+ summary = summarizer(pdf_content, max_length=100, min_length=30, do_sample=False)[0]['summary_text']
73
+
74
+ # Get the chat response
75
+ response = chat_with_pdf(question)
76
+
77
+ # Define the outputs
78
+ summary_output = gr.outputs.Textbox(label="Summary")
79
+ chat_output = gr.outputs.Textbox(label="Chat Response")
80
+
81
+ # Return the Gradio interface with the Multi output
82
+ return gr.Interface(
83
+ fn=chat_with_pdf,
84
+ inputs=[pdf_doc, question],
85
+ outputs=gradio.outputs.Multi(summary_output, chat_output),
86
+ examples=[["sample.pdf", "What is this document about?"]],
87
+ api_name='chat_with_pdf_2'
88
+ )
89
+
90
+ gradio_interface(None, None)
91
+
92
 
93
  gr.Interface(fn=gradio_interface,
94
  inputs=[gr.File(label="Load a pdf", file_types=['.pdf'], type="file"),