Last active
July 29, 2023 20:44
-
-
Save varunshenoy/f029c55536bb7e4fac61a595e836d930 to your computer and use it in GitHub Desktop.
This is an example of an Opendream serverless extension using Baseten that overrides the default `dream` function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import baseten | |
import base64 | |
from opendream import opendream | |
from opendream.layer import ImageLayer, Layer | |
@opendream.define_op | |
def dream(prompt: str): | |
# https://app.baseten.co/explore/stable_diffusion | |
# You can retrieve your deployed model version ID from the UI | |
# TODO: Deploy on Baseten and add your version ID | |
model = baseten.deployed_model_version_id('YOUR_VERSION_ID') | |
request = { | |
"prompt": f"{prompt}", | |
"scheduler": "ddim", | |
"negative_prompt": "blurry, disfigured, low resolution" | |
} | |
response = model.predict(request) | |
img=Layer.b64_to_pil(response["data"][0]) | |
return ImageLayer(image=img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment