| import gradio as gr |
| import requests |
| import io |
| import os |
| from PIL import Image |
|
|
|
|
| |
| API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0" |
| |
| headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"} |
| |
| |
| negative_prompts = [ |
| "porn", "pornography", "nude", "naked", "sex", "sexual", "erotic", |
| "explicit", "adult content", "xxx", "hentai", "fetish", "blowjob", |
| "intercourse", "masturbation", "orgasm", "stripper", "sexy", "lust", |
| "hardcore", "dirty", "inappropriate", "vulgar", "obscene", "raunchy", |
| "tits", "boobs", "penis", "vagina", "anal", "NSFW", "threesome", |
| "gangbang", "adult entertainment", "adult film", "camgirl", "camming", |
| "escort", "prostitution", "hardcore porn", "softcore", "smut", "BDSM", |
| "bondage", "domination", "submission", "submissive", "dominatrix", |
| "sadomasochism", "kinks", "nudity", "voyeur", "exhibitionism", "shemale", |
| "slut", "whore", "hooker", "escort service", "erotic massage", "sensual", |
| "foreplay", "handjob", "nude model", "porn star", "sexual fantasy", |
| "fetishism", "double penetration", "cumshot", "facial", "deepthroat", |
| "cock", "pussy", "dildo", "vibrator", "orgy", "swinger", "explicit content", |
| "provocative", "risqué", "titillating", "wet dream", "fuck","fucked","fucking","suck","sucking" |
| ] |
|
|
|
|
| |
| def query(payload): |
| response = requests.post(API_URL, headers=headers, json=payload) |
| response.raise_for_status() |
| return response.content |
|
|
| |
| def generate_image(input_text): |
| if any(neg_word in input_text.lower() for neg_word in negative_prompts): |
| return None, "The input contains a negative prompt. Image generation is blocked." |
| |
| image_bytes = query({"inputs": input_text}) |
| image = Image.open(io.BytesIO(image_bytes)) |
| return image,"" |
|
|
| |
| iface = gr.Interface( |
| fn=generate_image, |
| inputs=gr.Textbox(label="Input Text", placeholder="Enter your description here..."), |
| outputs=[gr.Image(label="Generated Image"), gr.Markdown(label="Message")], |
| title=" LodhranGPT Image Generator", |
| description="Enter a description to generate an image." |
| ) |
|
|
| |
| iface.launch() |
|
|