https://github.com/machinelearningzh/simply-simplify-language_api
Behördendeutsch-Removal as an API
https://github.com/machinelearningzh/simply-simplify-language_api
Last synced: over 1 year ago
JSON representation
Behördendeutsch-Removal as an API
- Host: GitHub
- URL: https://github.com/machinelearningzh/simply-simplify-language_api
- Owner: machinelearningZH
- License: mit
- Created: 2024-11-06T17:21:21.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-19T09:18:58.000Z (over 1 year ago)
- Last Synced: 2025-01-19T10:24:58.974Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 68.4 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Simple Simplifier API
**Simply Simplify German Language -- API Version**
This is a simplified version of our [Language Simplification Tool](https://github.com/machinelearningZH/simply-simplify-language).
With this version you can pip install the core functionality and use language simplification via GPT-4o as a package. The API is built with [FastAPI](https://fastapi.tiangolo.com/) and can be used to simplify German language text in production environments where you want to integrate programmatically with other services.
## Usage
- Create a [Conda](https://docs.anaconda.com/miniconda/) environment: `conda create -n simplifier python=3.9`
- Activate the environment: `conda activate simplifier`
- Clone this repository. Change into the project directory.
- Install the requirements: `pip install -r requirements.txt`
- Set the OpenAI API key, the MODEL_NAME and the Maximum tokens as an environment variables in env.
**Start the FastAPI server**
- `uvicorn fastapi_app:app --reload`
## Feedback and Contributions
Please share your feedback. You can [write an email](mailto:datashop@statistik.zh.ch) or share your ideas by opening an issue or a pull requests.
Please note, we use [Ruff](https://docs.astral.sh/ruff/) for linting and code formatting with default settings.
# How to use the API
### Route
```POST /```
***Description***
This endpoint simplifies a given input based on the provided payload. It supports a JSON object for the input data.
### Request Body
| Field | Type | Required | Description |
|-------------------|-----------|----------------|-------------------------------------------------------|
| `data` | `dict` | Yes | Json with a list of strings to simplifiy |
| `leichte_sprache` | `boolean` | No | If `True`, simplifies the text into plain language. |
| `model` | `gpt-4o` | No | Used for testing the OpenAI model, default is `gpt-4o` |
```POST /```
### JSON
```
{
"data": [
{
"text": "Als Vernehmlassungsverfahren wird diejenige Phase innerhalb des Vorverfahrens der Gesetzgebung bezeichnet, in der Vorhaben des Bundes von erheblicher politischer, finanzieller, wirtschaftlicher, ökologischer, sozialer oder kultureller Tragweite auf ihre sachliche Richtigkeit, Vollzugstauglichkeit und Akzeptanz hin geprüft werden. "
},
{
"text": "
Die Vorlage wird zu diesem Zweck den Kantonen, den in der Bundesversammlung vertretenen Parteien, den Dachverbänden der Gemeinden, Städte und der Berggebiete, den Dachverbänden der Wirtschaft sowie weiteren, im Einzelfall interessierten Kreisen unterbreitet.
"
}
]
}
```
### Response
```
{
"simplifications": [
{
"text": "Das Vernehmlassungsverfahren ist ein Teil der Gesetzgebung. In diesem Teil prüft der Bund wichtige Vorhaben. Der Bund prüft, ob die Vorhaben richtig, durchführbar und akzeptiert sind."
},
{
"text": "Der Bund legt den Vorschlag den Kantonen vor. Auch Parteien im Parlament sehen den Vorschlag. Verbände der Gemeinden, Städte und Berggebiete bekommen den Vorschlag. Wirtschaftsverbände und andere interessierte Gruppen sehen den Vorschlag auch."
}
]
}
```
***Responses***
200 OK: Successfully simplified the input data.
400 Bad Request: If the required fields are missing or the payload is not correctly formatted.
500 Internal Server Error: If an internal error occurs during processing (e.g., incorrect JSON format).
***Error Handling***
If the provided format is "json" but data is not a dictionary, the endpoint will raise a BadFormattingError.
Usage Notes
The leichte_sprache flag simplifies the content to plain language for easier understanding.