Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class ImageGeneratorHelper(private val context: Context) {
}

bitmap
} catch (e: SecurityException) {
throw e
} catch (e: Exception) {
Log.e(TAG, "Failed to generate image: ${e.message}", e)
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,27 @@ class StableDiffusionHelper(private val context: Context) {
}
}

val kidModeManager = com.llmhub.llmhub.utils.KidModeManager(context)
val isKidMode = kidModeManager.isKidModeEnabled.value

var finalPrompt = prompt
var finalNegativePrompt = negativePrompt

if (isKidMode) {
val lowerPrompt = prompt.lowercase()
val blockedWords = listOf("nsfw", "nude", "naked", "sex", "porn", "gore", "blood", "kill", "murder", "violence", "explicit","erotic", "hentai")
if (blockedWords.any { lowerPrompt.contains(it) }) {
throw SecurityException("Kid Mode violation: can't generate that.")
}

finalPrompt = "safe, family friendly, educational, $prompt"
finalNegativePrompt = "$negativePrompt, nsfw, nude, naked, sexually suggestive, explicit, gore, violence, blood, scary"
}

// Build JSON request body
val json = JSONObject().apply {
put("prompt", prompt)
put("negative_prompt", negativePrompt)
put("prompt", finalPrompt)
put("negative_prompt", finalNegativePrompt)
put("steps", steps)
put("cfg", cfg.toDouble())
if (seed != null) put("seed", seed)
Expand Down Expand Up @@ -349,6 +366,8 @@ class StableDiffusionHelper(private val context: Context) {
}

bitmap
} catch (e: SecurityException) {
throw e
} catch (e: Exception) {
Log.e(TAG, "Failed to generate image: ${e.message}", e)
null
Expand Down