A FastAPI-based API service for summarizing text and documents using large language models (LLMs).
Supports running models locally via Ollama or remotely via providers like OpenAI.
Ideal if you want to:
- Summarize arbitrary text
- Summarize uploaded documents (e.g. PDFs)
- Switch easily between local and cloud LLMs
- Summarize plain text
- Summarize uploaded PDF documents
- Use local Ollama LLMs for private, offline inference
- Or switch to cloud providers (e.g. OpenAI)
- JSON API endpoints
- Built with FastAPI
summarizeapi/
├── api/
│ └── v1/
│ ├── routes.py
├── core/
│ ├── llm_factory.py
│ └── summarizer.py
├── models/
│ └── summary_schema.py
├── services/
│ └── pdf_reader.py
├── utils/
│ └── config.py
└── main.py
main.py
– entry point for FastAPIroutes.py
– defines API endpointsllm_factory.py
– handles switching between Ollama / OpenAI / other providerspdf_reader.py
– extracts text from PDF uploadssummary_schema.py
– request/response models
-
Send plain text
- The API summarizes the text using the configured LLM.
-
Upload a document (PDF)
- Text is extracted from the PDF.
- The LLM summarizes the extracted text (or responds to your custom query).
Clone the repo:
git clone https://github.com/MIDHUNGRAJ/summarizeapi.git
cd summarizeapi
Create a virtual environment and install requirements:
conda create -n ml-engine python=3.11
conda activate ml-engine
pip install -r requirements.txt
Start the FastAPI server:
uvicorn summarizeapi.main:app --reload
Then visit:
http://127.0.0.1:8000/docs
to explore the interactive Swagger UI.
curl -X POST "http://127.0.0.1:8000/api/v1/summarize" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "text=Summarize this text quickly"
curl -X POST "http://127.0.0.1:8000/api/v1/summarize" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "text=Summarize the document content" \
-F "file=@yourfile.pdf;type=application/pdf"
- Add support for other document formats (Word, txt, etc.)
- Add support for more LLM providers (Anthropic, Mistral, etc.)
- Implement better error handling
- Add unit tests
MIT