https://github.com/donrestarone/serve_ai_model_as_rest_api_example
how to serve an AI model or checkpoint as a Python REST API example
https://github.com/donrestarone/serve_ai_model_as_rest_api_example
Last synced: about 2 months ago
JSON representation
how to serve an AI model or checkpoint as a Python REST API example
- Host: GitHub
- URL: https://github.com/donrestarone/serve_ai_model_as_rest_api_example
- Owner: donrestarone
- Created: 2024-03-02T15:56:11.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-03-02T16:10:51.000Z (about 1 year ago)
- Last Synced: 2025-01-14T08:52:38.617Z (3 months ago)
- Language: Python
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# README
This repository stands as an example on how to serve an AI Model / Checkpoint (from HuggingFace, CivitAI or where-ever) as a Python REST API.# Caveats
1. requests are processed in-line
2. if not CUDA, MPS is used. Please switch to CPU if you're running this in a non-CUDA and non-MPS environment (see here for guide: https://stackoverflow.com/questions/53266350/how-to-tell-pytorch-to-not-use-the-gpu)# installing dependencies
create/initialize python virtual environment``` bash
python3 -m venv .envsource .env/bin/activate
```install dependencies
``` bash
pip install -r requirements.txt
```# starting the server
``` bash
uvicorn api:app --reload --port 8001
```# sample request
POST localhost:8000/generate
```json
{"prompt": "photograph: 35mm 3/4 eye-level portrait, lighting: natural, subject: actress pin-up style, expression: amused, pose: cowboy-shot, background: industrial", "negative_prompt": "blurry, dark photo, blue, deformed body features, mutated body parts, disfigured"}
```# generated artifacts
Using this repository, the following images were generated. Prompts are included in the filename

















