Skip to content

donrestarone/serve_ai_model_as_rest_api_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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. Screen Shot 2024-03-02 at 11 01 01 AM

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

python3 -m venv .env

source .env/bin/activate

install dependencies

pip install -r requirements.txt

starting the server

uvicorn api:app --reload --port 8001

sample request

POST localhost:8000/generate

{"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

vitruvian-man_vaporwave1 vitruvian-man_--style_vaporwave1 sunset_blood_moon,_photograph_24mm,_airplane_flying_in_distance,_vaporwave1 photograph:_35mm_3-4_eye-level_portrait,_lighting:_natural,_subject:_actress_pin-up_style,_expression:_sultry,_pose:_holding_thunder,_background:_industrial1 photograph:_35mm_3-4_eye-level_portrait,_lighting:_natural,_subject:_actress_pin-up_style_bangs,_expression:_sultry,_pose:_holding_thunder,_background:_industrial1 photograph:_35mm_3-4_eye-level_portrait,_lighting:_natural,_subject:_actress_pin-up_style_bangs,_expression:_sultry,_pose:_facing_camera_hands_out-of-shot,_background:_industrial1 photograph:_35mm_3-4_aerial_shot,_lighting:_natural,_subject:_nuclear_explosion,_expression:_devestating,_background:_mountains_ocean1 photograph:_35mm_3-4_aerial_shot,_lighting:_natural,_subject:_northern_lights,_expression:_soothing,_background:_mountains_ocean1 photograph_35mm_point-of-view_house_underwater_fish_swimming_in_the_moonlight_natural_light1 photograph_24mm,_farmland,_animals,_crops,_sepia,_rainy_day1 nature mansion-in-appalachia landscape_with_water__1 girldiringpony-appalachia galactic-intelligence_blackhole_--style_vaporwave_1 galactic_waterfall_vaporwave1 galactic_intelligence_vaporwave_1 35mm_photograph_desert_daytime_mountains_camel_3-4_1 3-4_submerged_photograph_in_35mm,_POV_subject:_shark_in_the_ocean_natural-lighting_daytime1

About

how to serve an AI model or checkpoint as a Python REST API example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages