A Flask-based API that provides a user-friendly interface to summarize text in any language supported by the BART model and then translate it to English. This application offers both a web interface and an API endpoint for easy integration.
- Summarization: Employs Facebook's powerful BART-large-CNN model to condense text while retaining key information.
- Translation: Automatically detects the source language and translates the summary to English using the Helsinki-NLP Opus-MT model.
- Simple Web Interface: A clean, responsive web interface for inputting text and receiving the summarized and translated output.
- API Endpoint: A
/summarize
endpoint for seamless integration into other applications. - Configurable Summary Length: Users can specify minimum and maximum lengths for the summary.
- GPU Acceleration: Utilizes CUDA if available for faster processing.
- Rate Limiting: Implements rate limiting to prevent API abuse.
- Concurrent Processing: Uses a ThreadPoolExecutor for handling multiple requests efficiently.
- Health Check Endpoint: Includes a
/health
endpoint for monitoring the application's status.
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the app:
python app.py
-
Open your web browser and navigate to
http://localhost:5000/
. -
Enter your text, adjust the min and max length if desired, and click "Summarize".
Send a POST request to http://localhost:5000/summarize
with a JSON payload:
{
"text": "Your long text here",
"min_length": 30,
"max_length": 150
}
The API will return a JSON response:
{
"summary": "Translated summary of the text",
"detected_language": "fr" // Example: French
}
- Flask
- Transformers (Hugging Face)
- Langdetect
- PyTorch
- Flask-Limiter
- Summarization: Facebook BART-large-CNN
- Translation: Helsinki-NLP Opus-MT
- Summarization and translation quality can vary depending on the input text and language.
- The models have specific language capabilities. If a language is unsupported, the summary will be in the original language without translation.
- GPU acceleration requires a CUDA-compatible GPU.
- Adjust the rate limiting rules in
app.py
as needed. - The application uses the
PORT
environment variable if set, otherwise defaults to port 5000.
The application is configured to run on 0.0.0.0
and can use a port specified by the PORT
environment variable, making it suitable for deployment on various platforms.
Feel free to submit issues and pull requests to improve this project!
This project is licensed under the MIT License - see the LICENSE file for details.