{"id":20812215,"url":"https://github.com/curegit/stylegan-fastapi","last_synced_at":"2025-08-02T12:09:14.287Z","repository":{"id":135783808,"uuid":"532754224","full_name":"curegit/stylegan-fastapi","owner":"curegit","description":"Simplified Web REST API of the StyleGAN using FastAPI","archived":false,"fork":false,"pushed_at":"2024-11-27T04:31:32.000Z","size":219,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-25T02:08:40.310Z","etag":null,"topics":["chainer","fastapi","generative-adversarial-network","image-synthesis","openapi","stylegan2"],"latest_commit_sha":null,"homepage":"https://stylegan.curegit.jp","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/curegit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-05T05:21:21.000Z","updated_at":"2024-11-27T04:31:35.000Z","dependencies_parsed_at":"2024-11-12T02:29:32.943Z","dependency_job_id":"8a0c7783-a0e9-43dc-84fa-a54e8df8f174","html_url":"https://github.com/curegit/stylegan-fastapi","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/curegit/stylegan-fastapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Fstylegan-fastapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Fstylegan-fastapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Fstylegan-fastapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Fstylegan-fastapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/curegit","download_url":"https://codeload.github.com/curegit/stylegan-fastapi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/curegit%2Fstylegan-fastapi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268385861,"owners_count":24242105,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chainer","fastapi","generative-adversarial-network","image-synthesis","openapi","stylegan2"],"created_at":"2024-11-17T20:51:17.073Z","updated_at":"2025-08-02T12:09:14.244Z","avatar_url":"https://github.com/curegit.png","language":"Python","readme":"# StyleGAN FastAPI\n\nSimplified Web REST API of the StyleGAN using FastAPI\n\nThis is a web backend application to make the generator models trained by [Precure StyleGAN ADA](https://github.com/curegit/precure-stylegan-ada) available on the web in a simplified way.\n[StyleGAN Vue](https://github.com/curegit/stylegan-vue) is a sample implementation of its frontend client and is [deployed here](https://stylegan.curegit.jp/) connected to [a demo backend](https://stylegan.mermaid.blue/docs) with some models for immediate trial.\n\n[Sample Docker configurations](https://github.com/curegit/stylegan-web) for deploying StyleGAN models and the web-based user interface are also available.\n\n## API Specifications\n\nRefer to the [Swagger](https://stylegan.mermaid.blue/docs) or [ReDoc](https://stylegan.mermaid.blue/redoc) documentation on the sample backend or on your deployed instance at the paths `/docs` or `/redoc`.\n\n## Application Requirements\n\nTo run this application, you need a Unix-like system with Python \u003e= 3.12 installed.\n\nUse the `requirements.txt` to install the minimal dependencies for serving and inferencing, including the dependencies of [Precure StyleGAN ADA](https://github.com/curegit/precure-stylegan-ada).\n\n```sh\npip3 install -r requirements.txt\n```\n\nWhile Uvicorn is the recommended as ASGI middleware, other alternatives such as Hypercorn may also work.\nHowever, in a production environment, it is common to use process replication with a combination of Gunicorn and Uvicorn.\n\n## Quick Start: Running the default server\n\nThis repository contains the default server configuration using Uvicorn with some trained models.\nYou can quickly try it out as follows:\n\n```sh\ngit clone --recursive https://github.com/curegit/stylegan-fastapi.git\ncd stylegan-fastapi\npip3 install -r requirements.txt\npython3 -m uvicorn main:app\n```\n\nPlease note that this setup is intended for trial or debugging purposes only and is not suitable for production use as it does not support process replication.\n\n## Application Configuration\n\nStyleGAN FastAPI can be customized by using a configuration file.\nStyleGAN FastAPI uses the TOML format for configuration, and the default server's TOML file is located in `default/config.toml`.\n\nYou can specify a different configuration TOML file to use by setting the `STYLEGAN_TOML` environment variable.\n`STYLEGAN_TOML` must be an absolute TOML file path or a TOML file path relative to the working directory.\nNote that the `STYLEGAN_TOML` environment variable must be set before importing the `api/` Python package.\n\n```sh\nexport STYLEGAN_TOML=\"./custom_config.toml\"\nuvicorn main:app\n```\n\n### Configuration TOML Specifications\n\nThe configuration file follows the standard TOML format.\nA complete raw schema definition and its default values can be found in the `api/conf.py` Python file.\n\nAll properties are optional except the `file` field in `ModelConfig` to specify model files, and you must specify at least one model.\n\n#### General Settings (Root)\n\n| Key           | Type                                    | Description                                                          |\n| ------------- | --------------------------------------- | -------------------------------------------------------------------- |\n| `title`       | string                                  | The title of the API service. Used in the OpenAPI spec.              |\n| `version`     | string                                  | The version number of the API. Used in the OpenAPI spec.             |\n| `description` | string                                  | A brief description of the API service. Used in the OpenAPI spec.    |\n| `docs`        | boolean                                 | Whether the Swagger page is enabled. The default is `true`.          |\n| `redoc`       | boolean                                 | Whether the ReDoc page is enabled. The default is `true`.            |\n| `lossy`       | boolean                                 | Whether to use lossy compression for output. The default is `false`. |\n| `server`      | [ServerConfig](#serverconfig)           | Internal server configuration settings.                              |\n| `models`      | { string: [ModelConfig](#modelconfig) } | A dictionary of model configurations to use.                         |\n\n#### ServerConfig\n\n| Key       | Type                        | Description                                                                                                              |\n| --------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------ |\n| `gpu`     | boolean or int              | A boolean indicating whether GPU is enabled or an integer value specifying which GPU device is being used.               |\n| `logger`  | string                      | The name of the parent logger from which this application's logger is derived.                                           |\n| `tmp_dir` | string                      | The path to the temporary directory where the runtime files are located. Volatile locations such as `tmpfs` are allowed. |\n| `http`    | [HTTPConfig](#httpconfig)   | HTTP configuration settings.                                                                                             |\n| `limit`   | [LimitConfig](#limitconfig) | Limit configuration settings.                                                                                            |\n\n#### HTTPConfig\n\n| Key                 | Type                      | Description                                                                                                                                                                                                                                                                                                                    |\n| ------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `forwarded`         | boolean                   | Indicates whether reverse proxy servers are involved in the path of the requests. The default is `false`. You can leave this `false` if your middleware such as Uvicorn is configured to fill in real remote address info.                                                                                                     |\n| `forwarded_headers` | [string]                  | A list of headers to check for the original client address, such as \"Forwarded\" or \"X-Forwarded-For\", which can be multiple and is left in order. This is used for identifying clients when `forwarded` is true. Regardless of the header type, the entire string equivalence of the header value is used to identify clients. |\n| `cors`              | [CORSConfig](#corsconfig) | Cross-Origin Resource Sharing (CORS) configuration settings.                                                                                                                                                                                                                                                                   |\n\n#### CORSConfig\n\n| Key       | Type     | Description                                                                               |\n| --------- | -------- | ----------------------------------------------------------------------------------------- |\n| `enabled` | boolean  | A boolean value indicating whether CORS configuration is enabled. The default is `false`. |\n| `origins` | [string] | A list of allowed origins. Set `[\"*\"]` for wildcard.                                      |\n\n#### LimitConfig\n\n| Key           | Type                                              | Description                                             |\n| ------------- | ------------------------------------------------- | ------------------------------------------------------- |\n| `min_delay`   | float                                             | The minimum response delay time for CPU-bound requests. |\n| `block`       | [SignallingBlockConfig](#signallingblockconfig)   | A block of settings for the signalling block.           |\n| `concurrency` | [ConcurrencyLimitConfig](#concurrencylimitconfig) | A block of settings for the concurrency limit.          |\n| `rate`        | [RateLimitConfig](#ratelimitconfig)               | A block of settings for rate limiting.                  |\n\n#### SignallingBlockConfig\n\n| Key       | Type    | Description                                                                                                           |\n| --------- | ------- | --------------------------------------------------------------------------------------------------------------------- |\n| `enabled` | boolean | Whether the signalling block for CPU-bound requests (delaying simultaneous requests from the same client) is enabled. |\n| `timeout` | float   | The timeout duration in seconds for the signalling block.                                                             |\n| `poll`    | float   | The polling interval in seconds for the signalling block.                                                             |\n\n#### ConcurrencyLimitConfig\n\n| Key               | Type    | Description                                                      |\n| ----------------- | ------- | ---------------------------------------------------------------- |\n| `enabled`         | boolean | Whether the concurrency limit for CPU-bound requests is enabled. |\n| `max_concurrency` | int     | The maximum number of concurrent requests.                       |\n| `max_queue`       | int     | The maximum number of requests in the queue.                     |\n| `timeout`         | float   | The timeout duration in seconds for the concurrency limit.       |\n| `poll`            | float   | The polling interval in seconds for the concurrency limit.       |\n\n#### RateLimitConfig\n\n| Key           | Type    | Description                                                                         |\n| ------------- | ------- | ----------------------------------------------------------------------------------- |\n| `enabled`     | boolean | A boolean value indicating whether rate limiting for CPU-bound requests is enabled. |\n| `window`      | float   | The time window for rate limiting in seconds.                                       |\n| `max_request` | int     | The maximum number of requests allowed in the time window.                          |\n\n#### ModelConfig\n\n| Key           | Type           | Description                                                                                                                                                        |\n| ------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `file`        | string         | The path to the model file.                                                                                                                                        |\n| `relative`    | boolean        | Indicates whether the model file path is relative to this TOML file rather than the working directory. The default value is `false`.                               |\n| `name`        | string         | A display name of the model.                                                                                                                                       |\n| `description` | string         | A short description of the model.                                                                                                                                  |\n| `lossy`       | boolean        | Whether lossy compression is used. This overrides the `lossy` in the [General Settings](#general-settings-root).                                                   |\n| `gpu`         | boolean or int | A boolean indicating whether GPU is enabled or an integer value specifying which GPU device is being used. This overrides the [ServerConfig](#serverconfig) `gpu`. |\n\n## Gunicorn Tips\n\n### Merge Application Log into Gunicorn Log\n\nTo merge the application log into the Gunicorn log, set `logger = \"gunicorn.error\"` in the StyleGAN FastAPI TOML configuration file.\n\n### Derive Gunicorn Settings from `guni/conf.py`\n\nYou can customize how Gunicorn runs the application by overriding various options derived from sample Gunicorn settings.\n\n```py\nfrom guni.conf import *\n\nwsgi_app = \"main:app\"\nworkers = 3\nraw_env = [\"STYLEGAN_TOML=myconfig.toml\"]\n```\n\n### Using CUDA/CuPy with Gunicorn\n\nThere are certain limitations when using CUDA/CuPy.\n\nCUDA has a restriction that prevents processes from being forked after CUDA has been initialized.\nTo address this, set `preload = False` in Gunicorn settings so that CUDA is initialized in each forked process after Gunicorn creates child processes.\nNote that this approach will consume more RAM/VRAM.\n\nIf RAM/VRAM usage is a concern, it may be advisable to use Uvicorn alone even in production environments.\n\n## Service Configuration Example\n\n### `stylegan.service`\n\n```ini\n[Unit]\nDescription=Gunicorn StyleGAN Daemon\nRequires=stylegan.socket\nAfter=network.target\nAfter=syslog.target\n\n[Service]\nType=notify\nUser=spam\nGroup=spam\nWorkingDirectory=/home/spam/stylegan\nExecStart=/usr/local/bin/python3.12 -m gunicorn -c gunicorn.conf.py \\\n                                                --log-level info \\\n                                                --log-file /var/log/stylegan/system.log \\\n                                                --access-logfile /var/log/stylegan/access.log \\\n                                                --capture-output\nRuntimeDirectory=stylegan\nLogsDirectory=stylegan\nPrivateTmp=true\nExecReload=/bin/kill -s HUP $MAINPID\nKillMode=mixed\nTimeoutStartSec=240\nTimeoutStopSec=30\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\n```\n\nIf the volatile `/run` location is available via `RuntimeDirectory`, it is recommended to set as `tmp_dir = \"/run/stylegan\"` in the StyleGAN FastAPI TOML for improved disk IO performance.\n\n#### `stylegan.socket`\n\n```ini\n[Unit]\nDescription=Gunicorn StyleGAN Socket\n\n[Socket]\nListenStream=/run/stylegan.sock\nSocketUser=www-data\nSocketMode=600\n\n[Install]\nWantedBy=sockets.target\n```\n\n#### `logrotate.d/stylegan`\n\n```txt\n/var/log/stylegan/*.log {\n  monthly\n  dateformat -%Y-%m-%d\n  rotate 12\n  compress\n  ifempty\n  missingok\n  copytruncate\n  maxsize 100M\n}\n```\n\n## Notes\n\n- Ensure that proxy headers, if used, are set correctly (e.g., Forwarded, X-Forwarded-For) for production environments with a reverse proxy layer.\n- It is also recommended to set header and body size limits via Gunicorn or a reverse proxy.\n\n## License\n\n[CC BY-NC 4.0](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuregit%2Fstylegan-fastapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuregit%2Fstylegan-fastapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuregit%2Fstylegan-fastapi/lists"}