Skip to content

Commit

Permalink
comments and update
Browse files Browse the repository at this point in the history
  • Loading branch information
shiffman committed Nov 8, 2024
1 parent 42126ba commit 5edb85e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions 07-llms/ollama/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.1/p5.js"></script>
<meta charset="utf-8" />
</head>
<body>
<main></main>
<script src="sketch.js"></script>
</body>
</html>
14 changes: 13 additions & 1 deletion 08-image-models/sd-webui/sketch.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
// Introduction to Machine Learning for the Arts, Fall 2024
// https://github.com/ml5js/Intro-ML-Arts-IMA-F24
// In class demonstration

let promptInput;
let submitButton;
let img;
let loading = false;

function setup() {
createCanvas(400, 400);
// Input field for prompt
promptInput = createInput('A land of rainbows.');
// Button to submit prompt
submitButton = createButton('generate');
submitButton.mousePressed(generateImage);
}

function draw() {
background(220);
// Display loading text if image is being generated
if (loading) {
textAlign(CENTER, CENTER);
text('Loading...', width / 2, height / 2);
} else if (img) {
}
// Display generated image if available
else if (img) {
image(img, 0, 0, width, height);
}
}

async function generateImage() {
loading = true;
// Send POST request with user prompt to SD-webui running on ITP GPU machine
// https://github.com/AUTOMATIC1111/stable-diffusion-webui
const response = await fetch('http://itp-ml.itp.tsoa.nyu.edu:7860/sdapi/v1/txt2img', {
method: 'POST',
headers: {
Expand All @@ -32,6 +43,7 @@ async function generateImage() {
}),
});

// Parse the response
const data = await response.json();
img = createImg('data:image/png;base64,' + data.images[0], promptInput.value());
img.hide();
Expand Down

0 comments on commit 5edb85e

Please sign in to comment.