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

yey

parent f7620b1a
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# AI Miniproject 2 # AI Miniproject 2
Bla bla Bla bla
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# stability.ai & Stable diffusion # stability.ai & Stable diffusion
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import base64 import base64
import os import os
import requests import requests
engine_id = "stable-diffusion-512-v2-1" engine_id = "stable-diffusion-512-v2-1"
api_host = 'https://api.stability.ai' api_host = 'https://api.stability.ai'
api_key = 'sk-v1z1pueYOHD2Bu83YL9undyzC54WW89eJkCAI79e4zLLeje1' api_key = 'sk-v1z1pueYOHD2Bu83YL9undyzC54WW89eJkCAI79e4zLLeje1'
response = requests.post( response = requests.post(
f"{api_host}/v1/generation/{engine_id}/text-to-image", f"{api_host}/v1/generation/{engine_id}/text-to-image",
headers={ headers={
"Content-Type": "application/json", "Content-Type": "application/json",
"Accept": "application/json", "Accept": "application/json",
"Authorization": f"Bearer {api_key}" "Authorization": f"Bearer {api_key}"
}, },
json={ json={
"text_prompts": [ "text_prompts": [
{ {
"text": "A lighthouse on a cliff" "text": "A lighthouse on a cliff"
} }
], ],
"cfg_scale": 7, "cfg_scale": 7,
"clip_guidance_preset": "FAST_BLUE", "clip_guidance_preset": "FAST_BLUE",
"height": 512, "height": 512,
"width": 512, "width": 512,
"samples": 1, "samples": 1,
"steps": 30, "steps": 30,
}, },
) )
if response.status_code != 200: if response.status_code != 200:
raise Exception("Non-200 response: " + str(response.text)) raise Exception("Non-200 response: " + str(response.text))
data = response.json() data = response.json()
for i, image in enumerate(data["artifacts"]): for i, image in enumerate(data["artifacts"]):
with open(f"./out/v1_txt2img_{i}.png", "wb") as f: with open(f"./out/v1_txt2img_{i}.png", "wb") as f:
f.write(base64.b64decode(image["base64"])) f.write(base64.b64decode(image["base64"]))
``` ```
%% Cell type:markdown id: tags:
# OpenAI / ChatGPT
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
!pip install openai
``` ```
%% Cell type:code id: tags:
``` python
import os
import openai
text = "Generate 5 random scenes for some stock images as a csv"
# Load your API key from an environment variable or secret management service
openai.api_key = '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'
#'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'
response = openai.Completion.create(model="text-davinci-003", prompt=text, temperature=0, max_tokens=150)
answers = response.choices[0].text
print(response);
print(response.choices[0].text);
```
%% Output
random_scenes = [
["A woman in a white dress standing in a field of sunflowers",
"A man in a suit walking down a busy city street",
"A couple embracing on a beach at sunset",
"A family of four having a picnic in a park",
"A group of friends laughing around a campfire"],
["A woman in a red dress dancing in a nightclub",
"A man in a suit walking through a crowded market",
"A couple walking hand in hand through a forest",
"A family of four playing in a playground",
"A group of friends enjoying a sunset boat ride"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment