File size: 934 Bytes
d046658
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gradio as gr
from langchain import OpenAI, PromptTemplate
from langchain.chains.summarize import load_summarize_chain
from langchain.document_loaders import PyPDFLoader

import os

def summarize_pdf(pdf_file_path, contraseña, custom_prompt=""):
    loader = PyPDFLoader(pdf_file_path)
    docs = loader.load_and_split()

    os.environ["OPENAI_API_KEY"] = contraseña
    llm = OpenAI(temperature=0)

    chain = load_summarize_chain(llm, chain_type="map_reduce")
    summary = chain.run(docs)

    return summary

outputs = gr.outputs.Textbox(label="Summary")

iface = gr.Interface(
    fn=summarize_pdf,
    inputs=[gr.Textbox(label="Enter the PDF file url here"),
            gr.Textbox(lines=1, placeholder="Enter your API-key here...", label="API-Key:", type="password")
            ],
    outputs=outputs,
    title="PDF Summarizer",
    description="Enter the path to a PDF file and get its summary.",
)

iface.launch()