Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from langchain import OpenAI, PromptTemplate
|
| 3 |
+
from langchain.chains.summarize import load_summarize_chain
|
| 4 |
+
from langchain.document_loaders import PyPDFLoader
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
def summarize_pdf(pdf_file_path, contraseña, custom_prompt=""):
|
| 9 |
+
loader = PyPDFLoader(pdf_file_path)
|
| 10 |
+
docs = loader.load_and_split()
|
| 11 |
+
|
| 12 |
+
os.environ["OPENAI_API_KEY"] = contraseña
|
| 13 |
+
llm = OpenAI(temperature=0)
|
| 14 |
+
|
| 15 |
+
chain = load_summarize_chain(llm, chain_type="map_reduce")
|
| 16 |
+
summary = chain.run(docs)
|
| 17 |
+
|
| 18 |
+
return summary
|
| 19 |
+
|
| 20 |
+
outputs = gr.outputs.Textbox(label="Summary")
|
| 21 |
+
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=summarize_pdf,
|
| 24 |
+
inputs=[gr.Textbox(label="Enter the PDF file url here"),
|
| 25 |
+
gr.Textbox(lines=1, placeholder="Enter your API-key here...", label="API-Key:", type="password")
|
| 26 |
+
],
|
| 27 |
+
outputs=outputs,
|
| 28 |
+
title="PDF Summarizer",
|
| 29 |
+
description="Enter the path to a PDF file and get its summary.",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
iface.launch()
|