Skip to content
Snippets Groups Projects
Commit f7620b1a authored by Patrick Scheidegger's avatar Patrick Scheidegger
Browse files

fck off git

parent ff630815
Branches
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# AI Miniproject 2
Bla bla
%% Cell type:markdown id: tags:
# stability.ai & Stable diffusion
%% Cell type:code id: tags:
``` python
import base64
import os
import requests
engine_id = "stable-diffusion-512-v2-1"
api_host = 'https://api.stability.ai'
api_key = 'sk-v1z1pueYOHD2Bu83YL9undyzC54WW89eJkCAI79e4zLLeje1'
response = requests.post(
f"{api_host}/v1/generation/{engine_id}/text-to-image",
headers={
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {api_key}"
},
json={
"text_prompts": [
{
"text": "A lighthouse on a cliff"
}
],
"cfg_scale": 7,
"clip_guidance_preset": "FAST_BLUE",
"height": 512,
"width": 512,
"samples": 1,
"steps": 30,
},
)
if response.status_code != 200:
raise Exception("Non-200 response: " + str(response.text))
data = response.json()
for i, image in enumerate(data["artifacts"]):
with open(f"./out/v1_txt2img_{i}.png", "wb") as f:
f.write(base64.b64decode(image["base64"]))
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
# AI Miniproject 2
Bla bla
%% Cell type:markdown id: tags:
# stability.ai & Stable diffusion
%% Cell type:code id: tags:
``` python
import base64
import os
import requests
engine_id = "stable-diffusion-512-v2-1"
api_host = 'https://api.stability.ai'
api_key = 'sk-v1z1pueYOHD2Bu83YL9undyzC54WW89eJkCAI79e4zLLeje1'
response = requests.post(
f"{api_host}/v1/generation/{engine_id}/text-to-image",
headers={
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {api_key}"
},
json={
"text_prompts": [
{
"text": "A lighthouse on a cliff"
}
],
"cfg_scale": 7,
"clip_guidance_preset": "FAST_BLUE",
"height": 512,
"width": 512,
"samples": 1,
"steps": 30,
},
)
if response.status_code != 200:
raise Exception("Non-200 response: " + str(response.text))
data = response.json()
for i, image in enumerate(data["artifacts"]):
with open(f"./out/v1_txt2img_{i}.png", "wb") as f:
f.write(base64.b64decode(image["base64"]))
```
%% Cell type:code id: tags:
``` python
```
out/v1_txt2img_0.png

525 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment