|
| 1 | +import marimo |
| 2 | + |
| 3 | +__generated_with = "0.6.23" |
| 4 | +app = marimo.App() |
| 5 | + |
| 6 | + |
| 7 | +@app.cell |
| 8 | +def __(): |
| 9 | + import os |
| 10 | + import json |
| 11 | + |
| 12 | + import marimo as mo |
| 13 | + |
| 14 | + api_key = os.environ.get("SUBSTRATE_API_KEY") |
| 15 | + api_key = api_key or "YOUR_API_KEY" |
| 16 | + print(api_key) |
| 17 | + return api_key, json, mo, os |
| 18 | + |
| 19 | + |
| 20 | +@app.cell |
| 21 | +def __(api_key): |
| 22 | + from substrate import Substrate |
| 23 | + |
| 24 | + substrate = Substrate(api_key=api_key, base_url="https://api.substrate.run") |
| 25 | + return Substrate, substrate |
| 26 | + |
| 27 | + |
| 28 | +@app.cell |
| 29 | +def __(substrate): |
| 30 | + from substrate import GenerateImage, InterpolateFrames, StableDiffusionXLInpaint |
| 31 | + |
| 32 | + # Generate a base image |
| 33 | + base_image = GenerateImage(prompt="aerial view of ocean waves") |
| 34 | + |
| 35 | + # Generate variations |
| 36 | + times = [ |
| 37 | + "6am sunrise", |
| 38 | + "1pm afternoon bright sun", |
| 39 | + "8pm after sunset", |
| 40 | + ] |
| 41 | + images = [] |
| 42 | + for t in times: |
| 43 | + image = StableDiffusionXLInpaint( |
| 44 | + image_uri=base_image.future.image_uri, |
| 45 | + prompt=f"aerial view of rainforest, {t}", |
| 46 | + num_images=1, |
| 47 | + strength=0.9, |
| 48 | + ) |
| 49 | + images.append(image) |
| 50 | + |
| 51 | + # Interpolate from base through variations |
| 52 | + interpolate = InterpolateFrames( |
| 53 | + frame_uris=[ |
| 54 | + base_image.future.image_uri, |
| 55 | + images[0].future.outputs[0].image_uri, |
| 56 | + images[1].future.outputs[0].image_uri, |
| 57 | + images[2].future.outputs[0].image_uri, |
| 58 | + base_image.future.image_uri, |
| 59 | + ], |
| 60 | + num_steps=2, |
| 61 | + store="hosted", |
| 62 | + output_format="mp4", |
| 63 | + ) |
| 64 | + res = substrate.run(interpolate) |
| 65 | + return ( |
| 66 | + GenerateImage, |
| 67 | + InterpolateFrames, |
| 68 | + StableDiffusionXLInpaint, |
| 69 | + base_image, |
| 70 | + image, |
| 71 | + images, |
| 72 | + interpolate, |
| 73 | + res, |
| 74 | + t, |
| 75 | + times, |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +@app.cell |
| 80 | +def __(res): |
| 81 | + print(res.request_id) |
| 82 | + print(res) |
| 83 | + return |
| 84 | + |
| 85 | + |
| 86 | +@app.cell |
| 87 | +def __(interpolate, res): |
| 88 | + print(res.get(interpolate).video_uri) |
| 89 | + return |
| 90 | + |
| 91 | + |
| 92 | +@app.cell |
| 93 | +def __(interpolate, mo, res): |
| 94 | + mo.image(res.get(interpolate).video_uri) |
| 95 | + return |
| 96 | + |
| 97 | + |
| 98 | +@app.cell |
| 99 | +def __(images, mo, res): |
| 100 | + mo.vstack( |
| 101 | + [ |
| 102 | + mo.image(res.get(images[0]).outputs[0].image_uri), |
| 103 | + mo.image(res.get(images[1]).outputs[0].image_uri), |
| 104 | + mo.image(res.get(images[2]).outputs[0].image_uri), |
| 105 | + mo.image(res.get(images[3]).outputs[0].image_uri), |
| 106 | + ] |
| 107 | + ) |
| 108 | + return |
| 109 | + |
| 110 | + |
| 111 | +if __name__ == "__main__": |
| 112 | + app.run() |
0 commit comments