CoolFace
Apppublic

yumna7/NotebookLM

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py76 linesDownload Raw Back to root
1import google.generativeai as genai2import gradio as gr3import os4import fitz  # PyMuPDF5 6# 🔑 Configure Gemini API7api_key = os.getenv("YOUR_GEMINI_API_KEY")8genai.configure(api_key=api_key)9 10# اختر موديل Gemini11model = genai.GenerativeModel("gemini-1.5-flash")12 13# ---- Helper: استخراج النصوص من PDF ----14def extract_text_from_pdf(pdf_file):15    text = ""16    doc = fitz.open(pdf_file.name)17    for page in doc:18        text += page.get_text("text") + "\n"19    return text.strip()20 21# ---- Core function: Summarize with Gemini ----22def summarise_pdf(pdf_file):23    if pdf_file is None:24        return "⚠️ Please upload a PDF file."25    26    # 1. استخراج النص27    pdf_text = extract_text_from_pdf(pdf_file)28    29    # 2. تجهيز البرومبت30    prompt = f"""31    You are NotebookLM Quick Synthesiser inside Google AI Lab.32    The user uploaded a subsidy-regulation document.33    Please summarise **the key rules and important points** clearly.34 35    Text of document:36    {pdf_text[:5000]}  37 38    Format the summary as **Markdown** with:39    - Main Rules40    - Obligations41    - Exceptions / Notes42    """43    44    # 3. استدعاء Gemini45    response = model.generate_content(prompt)46    47    summary = response.text.strip()48    49    return summary50 51# ---- Gradio UI ----52with gr.Blocks() as demo:53    gr.Markdown("## 📝 Micro-Lab – NotebookLM Quick Synthesiser")54    gr.Markdown("Upload a subsidy-regulation PDF → Gemini will summarise key rules in Markdown.")55 56    with gr.Row():57        with gr.Column():58            pdf_input = gr.File(label="📂 Upload PDF", file_types=[".pdf"])59            summarise_btn = gr.Button("⚡ Summarise with NotebookLM")60        61        with gr.Column():62            output_md = gr.Markdown(value="⬅️ Upload a PDF and click Summarise.", elem_id="output-area")63 64    # ✅ نعرض رسالة loading قبل التنفيذ65    summarise_btn.click(66        fn=lambda x: "⏳ Summarising... please wait",67        inputs=pdf_input,68        outputs=output_md69    ).then(70        summarise_pdf,71        inputs=pdf_input,72        outputs=output_md73    )74 75demo.launch()76