semvec/pypi-packages huggingface dataset:
sd-server 0.1.0
Stable Diffusion server built with FastAPI
License: MIT

# Stable Diffusion Google Colab FastAPI Server

## Note: This is a pretty hacky server / client interface for generic Stable Diffusion pipelines using diffusers. It's not made for production use and hasn't really been optimized completely.

#### Installation

From pip:

```bash
pip install sd-server
```

From source:

```bash
git clone git@github.com:shyamsn97/stable-diffusion-server.git
cd stable-diffusion-server/
python setup.py install
```

### Stable Diffusion Server + Client Interface -- Simple Usage

Here we create a simple server hosting the standard `StableDiffusionPipeline`. The client takes in `**kwargs` that should be the arguments passed into the `__call__` function from the pipeline. For instance, the `StableDiffusionPipeline` `__call__` method can be found: https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L185. `host` and `port` can be specified in the `start` method for generic hosting.


```python
from sd_server import DiffusersServer, DiffusersClient
from diffusers import StableDiffusionPipeline

STABLE_DIFFUSION_PATH = "runwayml/stable-diffusion-v1-5" # this can be a local path
pipeline_kwargs = {
    "revision":"fp16",
    "torch_dtype":torch.float16
}
device = torch.device('cuda')

server = DiffusersServer.create(
    pretrained_path = STABLE_DIFFUSION_PATH,
    pipeline_cls = StableDiffusionPipeline,
    pipeline_kwargs = pipeline_kwargs,
    enable_attention_slicing = True,
    device = device
)
url = server.start(host="127.0.0.1", port=8000) # url -- either remote or local

# on another host / terminal
client = DiffusersClient(url)

responses = client(prompt='a photo of an astronaut riding a horse on mars', num_images_per_prompt=4) # this should return a list of images

```

### Serving from Google Colab

Using the server in Google Colab requires an [ngrok](https://ngrok.com/) account, and needs your ngrok auth token https://dashboard.ngrok.com/get-started/your-authtoken to be passed to the server. Note: Ngrok basically opens a tunnel from a dev machine to the cloud, which means its not really that secure, and should be used at your own risk. Read more here: https://stackoverflow.com/questions/36552950/is-ngrok-safe-to-use-or-can-it-be-compromised


```python
NGROK_AUTH_KEY = "your auth key from https://dashboard.ngrok.com/get-started/your-authtoken"

... # imports from above

server = DiffusersServer.create(
    pretrained_path = STABLE_DIFFUSION_PATH,
    pipeline_cls = StableDiffusionPipeline,
    pipeline_kwargs = pipeline_kwargs,
    enable_attention_slicing = True,
    device = device
)

url = server.start(ngrok_auth_token=NGROK_AUTH_KEY)

# on another host
client = DiffusersClient(url)

responses = client(prompt='a photo of an astronaut riding a horse on mars', num_images_per_prompt=4) # this should return a list of images
```
max-yaml 0.1.0
Creates dump, dumps, load, and load function for yaml doc based on the json stdlib.
License: MIT
Requires Python: >=3.10,<4.0

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<meta charset="utf-8"/>
	<title>README.md</title>
	<meta name="path" content="README.md"/>
	<meta name="author" content="Max Ludden"/>
	<meta name="date" content="2022-10-31 7:28 AM EST"/>
	<link type="text/css" rel="stylesheet" href="static/style.css"/>
	<meta name="url" content="https://github.com/maxludden/maxsetup/README.html ..."/>
	<meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body>

<h1><span class="github">maxludden</span>/<span class="repo">max_yaml</span></h1>

<p>This is a wrapper of PyYAML to make it easier to use. It creates functions similar to the stdlib&#8217;s &#8216;json&#8217; module.</p>

<h3 id="installation">Installation</h3>

<p>max_yaml can be installed from PyPi with your favorite package manager.</p>

<h4>pipx<span style="font-size:0.6em;">(recommended)</span></h4>

<pre><code class="bash">pipx install max_yaml
</code></pre>

<h4 id="pip">pip</h4>

<pre><code class="bash">pip install max_yaml
</code></pre>

<h4 id="poetry">poetry</h4>

<pre><code class="bash">poetry add max_yaml
</code></pre>

<h2 id="usage">Usage</h2>

<p>The helper functions are familiar to any developer familiar with the JSON module from the stdlib:</p>

<pre><code class="python">import max_yaml as yaml

yaml.dump(data, file)

yaml.dumps(data)

yaml.load(file)

yaml.loads(string)
</code></pre>

<p>There are also some helper functions mapped to the Safe Loader and Dumper from the PyYAML library:</p>

<pre><code class="python">import max_yaml as yaml

yaml.safe_dump(data, file)

yaml.safe_dumps(data)

yaml.safe_load(file)

yaml.safe_loads(string)
</code></pre>

<p>All of the functions are taking advantage of the faster <code>C</code> Loaders and Dumpers if they are available. If not, they will fall back to the slower <code>Python</code> versions.</p>

<h2 id="license">License</h2>

<div class="license">
    <h4>MIT License</h4>
    <p>Copyright (c) 2022 Maxwell Owen Ludden</p>
    <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
    <p>copies or substantial portions of the Software.</p>
    <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</div>

</body>
</html>