Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| import fitz # PyMuPDF | |
| # Load the summarization model from Hugging Face | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| # Function to extract text from the uploaded PDF | |
| def extract_text_from_pdf(pdf_file): | |
| doc = fitz.open(pdf_file.name) # β Use file path instead of .read() | |
| text = "" | |
| for page in doc: | |
| text += page.get_text() | |
| return text | |
| # Function to summarize the extracted text | |
| def summarize_pdf(pdf_file): | |
| try: | |
| text = extract_text_from_pdf(pdf_file) | |
| if len(text.strip()) == 0: | |
| return "β The PDF seems empty or has no extractable text." | |
| text = text[:3000] # Truncate to fit within model's token limit | |
| summary = summarizer(text, max_length=150, min_length=40, do_sample=False) | |
| return summary[0]['summary_text'] | |
| except Exception as e: | |
| return f"β Error: {str(e)}" | |
| # Gradio UI | |
| demo = gr.Interface( | |
| fn=summarize_pdf, | |
| inputs=gr.File(label="π Upload PDF of Academic Notes", type="file"), | |
| outputs=gr.Textbox(label="π Summarized Notes"), | |
| title="π Academic Note Summarizer", | |
| description="Upload a PDF of your academic notes. The app extracts and summarizes the content using a Hugging Face transformer model." | |
| ) | |
| # Launch the app | |
| demo.launch() | |