Spaces:
Running
Running
| import gradio as gr | |
| from transformers import pipeline | |
| import fitz # PyMuPDF for PDF reading | |
| # Summarizer model | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| def summarize_pdf(pdf_file): | |
| if pdf_file is None: | |
| return "Please upload a PDF file." | |
| # Reading PDF | |
| doc = fitz.open(pdf_file.name) | |
| text = "" | |
| for page in doc: | |
| text += page.get_text() | |
| if len(text) < 100: | |
| return "PDF me enough text nahi mila." | |
| # Summarization | |
| summary = summarizer(text, max_length=200, min_length=50, do_sample=False) | |
| return summary[0]["summary_text"] | |
| # Gradio UI | |
| interface = gr.Interface( | |
| fn=summarize_pdf, | |
| inputs=gr.File(label="Upload PDF here"), | |
| outputs="text", | |
| title="AI PDF Notes & Summary Maker", | |
| description="Upload any PDF and get instant summary." | |
| ) | |
| interface.launch() |