Spaces:
Runtime error
Runtime error
Download app.py from datagpt/pdf2summary: direct link, hf CLI and curl.
- Browser
- Download file 934 Bytes
-
https://huggingface.co/spaces/datagpt/pdf2summary/resolve/main/app.py
- Command line
-
hf download hf://spaces/datagpt/pdf2summary/app.py
-
curl -L -o app.py https://huggingface.co/spaces/datagpt/pdf2summary/resolve/main/app.py
934 Bytes
| 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() |