fahmindra commited on
Commit
f790a9a
1 Parent(s): bd6571d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import openai
4
+ from dotenv import load_dotenv, find_dotenv
5
+ from langchain import OpenAI, PromptTemplate
6
+ from langchain.chains.summarize import load_summarize_chain
7
+ from langchain.document_loaders import PyPDFLoader
8
+
9
+ _ = load_dotenv(find_dotenv())
10
+ openai.api_key = os.environ['OPENAI_API_KEY']
11
+ llm = OpenAI(temperature=0)
12
+
13
+ def pdf_summarizer(pdf):
14
+ loader = PyPDFLoader(pdf.name)
15
+ docs = loader.load_and_split()
16
+ chain = load_summarize_chain(llm, chain_type="map_reduce")
17
+ summary = chain.run(docs)
18
+ return summary
19
+
20
+ inputs = gr.File(label="Upload only a PDF file")
21
+ outputs = gr.Textbox(label="PDF Summary")
22
+
23
+ iface = gr.Interface(
24
+ fn=pdf_summarizer,
25
+ inputs=inputs,
26
+ outputs=outputs
27
+ title="PDF Summarizer",
28
+ )
29
+
30
+ iface.launch()