diff --git a/go.mod b/go.mod index dac5d40..218c273 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,10 @@ module danlegt.com/stablediffusion-friends go 1.20 -require github.com/gin-gonic/gin v1.9.0 +require ( + github.com/TwiN/go-away v1.6.10 + github.com/gin-gonic/gin v1.9.0 +) require ( github.com/bytedance/sonic v1.8.8 // indirect diff --git a/go.sum b/go.sum index 1c6b954..1fb9b1e 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/TwiN/go-away v1.6.10 h1:ScxGvhyJPu7VqLJJCpVx9vXBlQXi4wme3Vwx4z1WeC4= +github.com/TwiN/go-away v1.6.10/go.mod h1:e0adzvKFM6LIbU+K8pczlqYMaoH/6OwdvQEqg9wSRSU= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.8.8 h1:Kj4AYbZSeENfyXicsYppYKO0K2YWab+i2UTSY7Ukz9Q= github.com/bytedance/sonic v1.8.8/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= diff --git a/main.go b/main.go index 7c94322..596d167 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "net/http" "danlegt.com/stablediffusion-friends/lib/rtypes" + goaway "github.com/TwiN/go-away" "github.com/gin-gonic/gin" ) @@ -32,6 +33,11 @@ func main() { imageDescriptior := c.PostForm("image_description") + if goaway.IsProfane(imageDescriptior) { + imageDescriptior = goaway.Censor(imageDescriptior) + fmt.Printf("Found profanity, censoring to: %s\n", imageDescriptior) + } + // Build the request request := rtypes.SDTextToImageRequest{ Prompt: imageDescriptior, @@ -41,7 +47,7 @@ func main() { CfgScale: 8, Width: 512, Height: 512, - NegativePrompt: "nsfw, porn, naked, nude, nipple, penis, dick, vagina, asshole, visible nipple, nsfl, not safe for work, nudity, artifact, deformed, multiple limbs, ugly, gore, blood, sex, pornography", + NegativePrompt: "nsfw, porn, naked, nude, nipple, penis, dick, vagina, asshole, visible nipple, nsfl, not safe for work, nudity, artifact, deformed, multiple limbs, ugly, gore, blood, sex, pornography, penis, dick, genitalia, male genitalia, anus, penetration, double penetration, cock", SamplerIndex: "Euler", SendImages: true, SaveImages: false, @@ -102,7 +108,9 @@ func main() { newImage, newImagesToDisplay := imagesToDisplay[0], imagesToDisplay[1:] // Actually pop it - imagesToDisplay = newImagesToDisplay + if 3 > 2 { + imagesToDisplay = newImagesToDisplay + } c.JSON(200, gin.H{ "image": newImage, diff --git a/public/js/main.js b/public/js/main.js index 5536225..e84d364 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -8,6 +8,7 @@ const randomPrompts = [ ] var generatedImage = ``; +var generatedImageDownloadBase64 = ``; var nextSubmitAllowedTime = 0; function generateRandomPrompt() { @@ -101,6 +102,15 @@ async function handleImageGeneratorForm() { }) + imageGeneratorForm.querySelector(`#download-image-button`).addEventListener( `click`, e => { + e.preventDefault(); + + if ( !!generatedImageDownloadBase64 ) { + window.location.href = 'data:application/octet-stream;base64,' + generatedImageDownloadBase64; + } + + }) + imageGeneratorForm.querySelector(`#submit-image-button`).addEventListener( `click`, async (e) => { // Cancel the default post, we wills end the data to an API endpoint @@ -181,6 +191,7 @@ async function handleImageGeneratorForm() { document.getElementById(`submit-image-button`).removeAttribute(`disabled`); generatedImage = r.images[0]; + generatedImageDownloadBase64 = r.images[0]; }) } diff --git a/templates/home/index.html b/templates/home/index.html index d9d21d3..4e76967 100644 --- a/templates/home/index.html +++ b/templates/home/index.html @@ -62,20 +62,13 @@
- +
- - + +
- + +