* More Stuff

This commit is contained in:
Daniel Legt 2023-05-01 22:17:04 +03:00
parent eea5b6cdf4
commit ebf0812920
5 changed files with 32 additions and 15 deletions

5
go.mod
View File

@ -2,7 +2,10 @@ module danlegt.com/stablediffusion-friends
go 1.20 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 ( require (
github.com/bytedance/sonic v1.8.8 // indirect github.com/bytedance/sonic v1.8.8 // indirect

2
go.sum
View File

@ -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.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 h1:Kj4AYbZSeENfyXicsYppYKO0K2YWab+i2UTSY7Ukz9Q=
github.com/bytedance/sonic v1.8.8/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.8.8/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=

10
main.go
View File

@ -7,6 +7,7 @@ import (
"net/http" "net/http"
"danlegt.com/stablediffusion-friends/lib/rtypes" "danlegt.com/stablediffusion-friends/lib/rtypes"
goaway "github.com/TwiN/go-away"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -32,6 +33,11 @@ func main() {
imageDescriptior := c.PostForm("image_description") 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 // Build the request
request := rtypes.SDTextToImageRequest{ request := rtypes.SDTextToImageRequest{
Prompt: imageDescriptior, Prompt: imageDescriptior,
@ -41,7 +47,7 @@ func main() {
CfgScale: 8, CfgScale: 8,
Width: 512, Width: 512,
Height: 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", SamplerIndex: "Euler",
SendImages: true, SendImages: true,
SaveImages: false, SaveImages: false,
@ -102,7 +108,9 @@ func main() {
newImage, newImagesToDisplay := imagesToDisplay[0], imagesToDisplay[1:] newImage, newImagesToDisplay := imagesToDisplay[0], imagesToDisplay[1:]
// Actually pop it // Actually pop it
if 3 > 2 {
imagesToDisplay = newImagesToDisplay imagesToDisplay = newImagesToDisplay
}
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"image": newImage, "image": newImage,

View File

@ -8,6 +8,7 @@ const randomPrompts = [
] ]
var generatedImage = ``; var generatedImage = ``;
var generatedImageDownloadBase64 = ``;
var nextSubmitAllowedTime = 0; var nextSubmitAllowedTime = 0;
function generateRandomPrompt() { 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) => { imageGeneratorForm.querySelector(`#submit-image-button`).addEventListener( `click`, async (e) => {
// Cancel the default post, we wills end the data to an API endpoint // 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`); document.getElementById(`submit-image-button`).removeAttribute(`disabled`);
generatedImage = r.images[0]; generatedImage = r.images[0];
generatedImageDownloadBase64 = r.images[0];
}) })
} }

View File

@ -62,20 +62,13 @@
</div> </div>
</div> </div>
<div style="display: flex; flex-flow: column; padding: 0; margin: 0; margin-top: .5rem"> <div style="display: flex; flex-flow: column; padding: 0; margin: 0; margin-top: .5rem">
<textarea name="image_description" <textarea name="image_description" id="image_description" rows="10" class="t95"></textarea>
id="image_description"
rows="10"
class="t95"></textarea>
<div style="display: flex; flex-flow: row; align-items: center; justify-content: center; margin: .5rem 0"> <div style="display: flex; flex-flow: row; align-items: center; justify-content: center; margin: .5rem 0">
<button class="btn-95" <button class="btn-95" style="width: calc(50% - .25rem); margin-right: .25rem">Generate Image</button>
style="width: calc(50% - .5rem); margin-right: .5rem" <button class="btn-95" style="width: calc(50% - .25rem); margin-left: .25rem" id="random-prompt-button">Random Prompt</button>
id="random-prompt-button">Random Prompt</button>
<button class="btn-95"
style="width: calc(50% - .5rem); margin-left: .5rem">Generate Image</button>
</div> </div>
<button class="btn-95" <button class="btn-95" id="download-image-button" style="margin-bottom: .5rem">Download Image</button>
id="submit-image-button" <button class="btn-95" id="submit-image-button" disabled >Submit Image</button>
disabled>Submit Image</button>
</div> </div>
</form> </form>
</aside> </aside>