Automatically extract bibliographic metadata from research paper PDFs using Google Gemini AI.
- 📄 Extracts metadata from PDF research papers
- 🤖 Uses Google Gemini 2.5 Flash AI model
- 📊 Exports results to JSON
- 🔄 Incremental processing (resumes where you left off)
- 🎯 Extracts: Title, Authors, Year, Journal, DOI, Keywords, Abstract
pip install google-genai PyPDF2 python-dotenvCreate a .env file:
GEMINI_API_KEY=your-api-key-hereGet your free API key: https://aistudio.google.com/app/apikey
python3 extract_metadata.pyWhen prompted, enter the path to your PDF folder (e.g., pdf or /path/to/pdfs).
python3 test_gemini.pyThe script creates two files:
metadata.json- Contains all extracted metadataprocessed_files.json- Tracks which files have been processed
{
"title": "Machine Learning in Healthcare",
"authors": ["John Doe", "Jane Smith"],
"year": "2024",
"journal": "AI in Medicine",
"doi": "10.1234/example",
"keywords": ["machine learning", "healthcare", "AI"],
"abstract": "This paper explores...",
"filename": "paper.pdf",
"relative_path": "papers/paper.pdf"
}- Extracts text from first 3 pages of each PDF (using PyPDF2)
- Sends text to Google Gemini AI
- Parses response as JSON metadata
- Saves results incrementally (survives interruptions)
- ✅ Processes PDFs recursively in subdirectories
- ✅ Skips already processed files
- ✅ Resume capability if interrupted
- ✅ Automatic retry on API errors
- ✅ Debug output for troubleshooting
Reset and start fresh:
rm processed_files.json metadata.json
python3 extract_metadata.pyView results:
cat metadata.json | python3 -m json.tool- Python 3.7+
- Google Gemini API key (free tier available)
- PDF files with text (not scanned images)