CoolFace
Apppublic

aakash0563/pdf_summarization

sourceHugging Faceotherupdated 3y agoView on Hugging Face
1likes
app.py41 linesDownload Raw Back to root
1from langchain.llms import GooglePalm2from langchain.prompts import PromptTemplate3import gradio as gr4import pdfplumber5 6api_key = 'AIzaSyDiDVR0LcoIakZvLXbDbA3W861X0ctDt38' # get this free api key from https://makersuite.google.com/7 8llm = GooglePalm(google_api_key=api_key, temperature=0.1)9 10def extract_text(file_path):11    with open(file_path, 'rb') as f:12        pdf = pdfplumber.open(f)13        text = ""14        for page in pdf.pages:15            text += page.extract_text()16        prompt_template = PromptTemplate.from_template("""17 18        **Q:** Make important notes and extract important information from the given below PDF text that is asked in any competitive exam.19 20        **PDF Text:**21 22        ```23        {PDF_text}24        ```25 26        **A:**27 28        ```29        [Notes and important information]30        ```"""31        )32        prompt = prompt_template.format(PDF_text=text)33        return llm(prompt)34demo = gr.Interface(35    fn=extract_text,36    inputs="file",37    outputs="text",38    description="Extract Important inforamtion from PDF file",39    )40 41demo.launch(debug=True)