|
Download README.md from imkrish/certificate-generator: direct link, hf CLI and curl.
- Browser
- Download file 4.32 kB
-
https://huggingface.co/spaces/imkrish/certificate-generator/resolve/main/README.md
- Command line
-
hf download hf://spaces/imkrish/certificate-generator/README.md
-
curl -L -o README.md https://huggingface.co/spaces/imkrish/certificate-generator/resolve/main/README.md
4.32 kB
metadata
title: Certificate Generator
emoji: π
colorFrom: blue
colorTo: green
sdk: docker
sdk_version: '1.0'
app_file: api_main.py
app_port: 7860
pinned: false
Certificate Generator API
A FastAPI-based service for generating professional certificates with customizable templates, logos, signatures, and text.
Features
- Generate certificates with custom templates
- Support for multiple certificate types (participation/achievement)
- Configurable logo placement and sizing
- Digital signature support with signatory details
- Custom font support
- Automated text wrapping and positioning
- PDF output format
Prerequisites
- Python 3.8+
- Required Python packages (see
requirements.txt) - Storage space for templates, uploads, and generated certificates
Installation
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Directory Structure
The API automatically creates the following directory structure:
certificate_generator/
βββ uploads/ # For logos and signatures
βββ templates/ # Certificate template images
βββ fonts/ # Custom font files
βββ generated_certificates/ # Output directory for PDFs
Configuration
The API uses a JSON-based configuration system with these main components:
- Certificate type (participation/achievement)
- Name settings (position, font, size)
- Award text settings
- Logo settings (left/right)
- Signatory settings (left/right)
Default configuration is provided but can be customized via API endpoints.
API Endpoints
Information
GET /- API documentation and workflowGET /status- Check API readiness and configuration status
Configuration
GET /config- Get current configurationGET /config/defaults- Get default configurationPOST /config/certificate-type- Set certificate typePOST /config/name-settings- Configure name placementPOST /config/award-text- Configure award textPOST /config/logo-left- Configure left logoPOST /config/logo-right- Configure right logoPOST /config/signatory-left- Configure left signatoryPOST /config/signatory-right- Configure right signatoryPOST /config/reset- Reset to default configuration
File Upload
POST /upload-template- Upload certificate templatePOST /upload-logo- Upload logo imagePOST /upload-signature- Upload signature imagePOST /upload-font- Upload custom font file
Certificate Generation
POST /generate- Generate certificates for list of namesGET /download/{filename}- Download generated certificate
Management
GET /files- List all uploaded and generated filesDELETE /clear-generated- Clear generated certificates
Usage Example
- Upload certificate template:
curl -X POST "http://localhost:7860/upload-template" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "file=@template.png" \
-F "template_type=participation"
- Configure settings:
curl -X POST "http://localhost:7860/config/award-text" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{
"text": "For outstanding participation in the CSI Workshop 2025",
"position": {"x": 810, "y": 720},
"font_size": 45,
"max_width": 1000
}'
- Generate certificates:
curl -X POST "http://localhost:7860/generate" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{
"names": ["John Doe", "Jane Smith"]
}'
Running the API
Start the server:
python api_main.py
The API will be available at:
- API Documentation: http://localhost:7860/docs
- API Root: http://localhost:7860/
Error Handling
The API provides detailed error messages for:
- Missing required files
- Invalid file formats
- Configuration errors
- Generation failures
Security Considerations
- CORS is enabled for all origins
- File type validation for uploads
- Size limits for uploaded files
- Path traversal prevention
Additional Notes
- Recommended template resolution: 2000x1500 pixels or higher
- Supported image formats: PNG (recommended), JPEG
- Font format: TTF only
- Default font: DancingScript-Regular.ttf
- Certificate output format: PDF