This project provides a REST API to extract contract metadata such as:
- Award Criteria
- Solvency Criteria
- Special Execution Conditions
The extraction is based on text documents using OpenAI's GPT-4o-mini model.
The API processes raw text input and returns a structured JSON output with the extracted information.
- 📡 REST API for contract metadata extraction.
- 🤖 Developed using OpenAI GPT-4o-mini.
- 📄 Supports plain text as input.
- 🧠 Automatic extraction of 3 categories:
- Award Criteria
- Solvency Criteria
- Special Execution Conditions
- 📜 Logging system.
- 🐳 Dockerized for easy deployment.
.
├── app
│ ├── main.py # Main Flask application
│ └── requirements.txt # Python dependencies
├── .env # Environment variables (API key)
├── .gitignore # Git ignore file
├── Dockerfile # Docker build file
├── docker-compose.yml # Docker Compose setup
└── README.md # This documentation
git clone https://github.com/your-repo/metadata-extraction-api.git
cd metadata-extraction-apiCreate a .env file in the root directory and add your OpenAI API key:
OPENAI_API_KEY=sk-your-api-keyYou can obtain an API key by registering at OpenAI's API platform.
docker build -t metadata-api .docker run -p 5000:5000 --env-file .env metadata-apidocker-compose up --buildThis will expose the API at http://localhost:5000/extract_metadata.
POST /extract_metadata
| Field | Type | Description |
|---|---|---|
text |
string | Plain text content to analyze |
curl -X POST "http://localhost:5000/extract_metadata" -H "Content-Type: application/json" -d '{
"text": "This contract is awarded based on financial and technical criteria..."
}'{
"criterios_adjudicacion": "Award criteria extracted...",
"criterios_solvencia": "Solvency criteria extracted...",
"condiciones_especiales": "Special conditions extracted..."
}- The
textfield must contain plain text. - The API automatically processes large text inputs by splitting them into smaller sections before analysis.
- Logs are printed directly to the console when running the container.
- You can extend logging to file inside
app/main.pyif needed.
To stop and remove the containers:
docker-compose downTo prune unused images and containers:
docker system prune -aOPENAI_API_KEY=sk-your-openai-api-keyIf you want to run it locally without Docker:
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r app/requirements.txtpython app/main.pyAPI will be available at http://localhost:5000/extract_metadata.
This version is optimized for direct text-based metadata extraction and supports large text inputs efficiently. 🚀
This work has received funding from the NextProcurement European Action (grant agreement INEA/CEF/ICT/A2020/2373713-Action 2020-ES-IA-0255).
