Spaces:
Running
Running
File size: 1,678 Bytes
c711344 a81713a b0a4c4e 9b96ec1 b77baa1 95fd18e b77baa1 95fd18e b77baa1 e9759f4 b77baa1 e9759f4 b77baa1 95fd18e 91a909a e1c8315 a241a87 f852c0f a81713a a241a87 95fd18e 0aaa2ca a241a87 a81713a 397bbf6 b46e490 a241a87 397bbf6 31f6495 b0758dc 31f6495 |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
from langchain_community.document_loaders import PyPDFLoader
import gradio as gr
from langchain.chains.summarize import load_summarize_chain
from huggingface_hub import InferenceClient
from langchain_huggingface import HuggingFaceEndpoint
import os
# Set your Hugging Face token securely
HUGGINGFACEHUB_API_TOKEN = os.environ["HUGGINGFACEHUB_API_TOKEN"]
# Create the LLM
#llm = HuggingFaceHub(
# repo_id="facebook/bart-large-cnn", # Summarization-capable model
# model_kwargs={"temperature": 0.7, "max_length": 512}
#)
repo_id = "google/gemma-3-12b-it"
llm = HuggingFaceEndpoint(
repo_id=repo_id,
temperature=0.5,
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
provider="featherless-ai", # set your provider here hf.co/settings/inference-providers
# provider="hyperbolic",
# provider="nebius",
# provider="together",
)
#TEXT_MODEL_NAME = "google/gemma-3-270m"
loader = PyPDFLoader("http://arxiv.org/pdf/2508.13246v1")
documents = loader.load()
#llm = OpenAI(temperature=0)
def summarize_pdf (pdf_file_path, custom_prompt=""):
loader = PyPDFLoader(pdf_file_path)
docs = loader.load_and_split()
chain = load_summarize_chain(llm, chain_type="map_reduce")
summary = chain.invoke(docs)
return summary
input_pdf_path = gr.Textbox(label="Enter the PDF file path")
output_summary = gr.Textbox(label="Summary")
interface = gr.Interface(
fn = summarize_pdf,
inputs = input_pdf_path,
outputs = output_summary,
title = "PDF Summarizer",
description = "This app allows you to summarize your PDF files.",
)
#demo.launch(share=True)
if __name__ == "__main__":
interface.launch(share=True)
|