Public
Edited
Jul 19, 2023
Paused
3 forks
Importers
23 stars
Insert cell
Insert cell
Insert cell
gr = import("@gradio/client")
Insert cell
Insert cell
hello = gr.client("gradio/hello_blocks")
Insert cell
Insert cell
Insert cell
helloResult = hello.predict("/greet", ["This is me from Observable"])
Insert cell
Insert cell
helloResult.data
Insert cell
Insert cell
Insert cell
sd = gr.client("stabilityai/stable-diffusion")
Insert cell
Insert cell
sd.view_api()
Insert cell
Insert cell
Insert cell
Insert cell
result = sd.predict(1, [
sd_values.prompt,
sd_values.negative_prompt,
sd_values.guidance_scale
])
Insert cell
Insert cell
html`
<div style="max-width:40rem;display:grid;gap:1rem;grid-template-columns: 1fr 1fr;">
${result.data[0].map((entry) => {
const img = new Image();
img.src = entry[0].data;
img.style.width = "100%";
return img;
})}
</div>
`
Insert cell
Insert cell
Insert cell
captioning = gr.client("nielsr/comparing-captioning-models")
Insert cell
captioningApi = captioning.view_api()
Insert cell
Insert cell
imageCaptions = captioning.predict("/predict", [
await FileAttachment("cats.jpeg").blob()
])
Insert cell
Insert cell
Inputs.table(
captioningApi.named_endpoints["/predict"].returns.map((r, i) => ({
label: r.label,
result: imageCaptions.data[i]
}))
)
Insert cell
Insert cell
Insert cell
eleven = gr.client("elevenlabs/tts")
Insert cell
eleven.view_api()
Insert cell
Insert cell
elevenResult = eleven.predict(0, [
tts_values.text,
tts_values.voice,
"eleven_multilingual_v1"
])
Insert cell
Insert cell
html`
<audio controls>
<source src="${elevenResult.data[0].data}" type="audio/x-wav">
</audio>`
Insert cell
Insert cell
Insert cell
chatStreaming = gr.client("ysharma/RedPajama-Chat-3B")
Insert cell
chatStreaming.view_api()
Insert cell
Insert cell
Insert cell
chatStreamingResult = {
// status: "pending" | "error" | "complete" | "generating";
let status = "";
let data = null;
yield { status, data };
chatStreaming
.submit(3, [[[chatQuestion, ""]], 0.95, 500, 1])
.on("status", (evt) => (status = evt.stage))
.on("data", (evt) => (data = evt.data[0]));

while (status !== "error" && status !== "complete") {
yield { status, data };
}
yield { status, data };
}
Insert cell
Insert cell
Insert cell
import { guard } from "@mootari/inputs-submit"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more