Spaces:
Sleeping
Sleeping
Download summarizer.py from chburhan64/PDF_Agent: direct link, hf CLI and curl.
- Browser
- Download file 782 Bytes
-
https://huggingface.co/spaces/chburhan64/PDF_Agent/resolve/main/summarizer.py
- Command line
-
hf download hf://spaces/chburhan64/PDF_Agent/summarizer.py
-
curl -L -o summarizer.py https://huggingface.co/spaces/chburhan64/PDF_Agent/resolve/main/summarizer.py
782 Bytes
| from langchain.chains.combine_documents import create_stuff_documents_chain | |
| from langchain_core.prompts import ChatPromptTemplate | |
| def get_summary_prompt(): | |
| """Get the prompt template for document summarization""" | |
| return ChatPromptTemplate.from_template(""" | |
| You are a helpful assistant. Summarize the following document clearly and accurately: | |
| <context> | |
| {context} | |
| </context> | |
| """) | |
| def summarize_document(llm, documents): | |
| """ | |
| Summarize the uploaded document(s) | |
| Args: | |
| llm: Language model instance | |
| documents: List of document chunks | |
| Returns: | |
| str: Document summary | |
| """ | |
| summary_prompt = get_summary_prompt() | |
| chain = create_stuff_documents_chain(llm, summary_prompt) | |
| return chain.invoke({"context": documents}) |