drdudddd commited on
Commit
5224c49
·
verified ·
1 Parent(s): 1535086

Upload 3 files

Browse files
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
4
+ import os
5
+
6
+ # Modell-ID (Unzensiertes Modell basierend auf SD 1.5)
7
+ model_id = "Kernel/sd-nsfw"
8
+
9
+ # Lade die Pipeline
10
+ # Wir nutzen float32 für CPU, da dies am stabilsten ist.
11
+ # safety_checker=None deaktiviert den eingebauten Filter.
12
+ print("Lade Modell...")
13
+ pipe = StableDiffusionPipeline.from_pretrained(
14
+ model_id,
15
+ torch_dtype=torch.float32,
16
+ safety_checker=None,
17
+ requires_safety_checker=False
18
+ )
19
+
20
+ # Nutze einen schnelleren Scheduler für CPU
21
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
22
+ pipe = pipe.to("cpu")
23
+
24
+ def generate_image(prompt, negative_prompt, steps, guidance_scale):
25
+ print(f"Generiere Bild für: {prompt}")
26
+ image = pipe(
27
+ prompt=prompt,
28
+ negative_prompt=negative_prompt,
29
+ num_inference_steps=int(steps),
30
+ guidance_scale=guidance_scale
31
+ ).images[0]
32
+ return image
33
+
34
+ # Gradio Interface
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("# 🎨 Unzensierter KI-Bildgenerator (CPU-optimiert)")
37
+ gr.Markdown("Diese App nutzt das Modell `Kernel/sd-nsfw` auf Hugging Face Spaces (CPU).")
38
+
39
+ with gr.Row():
40
+ with gr.Column():
41
+ prompt = gr.Textbox(label="Prompt", placeholder="Was möchtest du sehen?", lines=3)
42
+ negative_prompt = gr.Textbox(label="Negativer Prompt", placeholder="Was soll nicht im Bild sein?", value="low quality, blurry, distorted")
43
+
44
+ with gr.Row():
45
+ steps = gr.Slider(minimum=1, maximum=50, value=20, step=1, label="Inferenz-Schritte (CPU: 20 empfohlen)")
46
+ guidance_scale = gr.Slider(minimum=1, maximum=20, value=7.5, step=0.5, label="Guidance Scale")
47
+
48
+ generate_btn = gr.Button("Bild generieren", variant="primary")
49
+
50
+ with gr.Column():
51
+ output_image = gr.Image(label="Generiertes Bild")
52
+
53
+ generate_btn.click(
54
+ fn=generate_image,
55
+ inputs=[prompt, negative_prompt, steps, guidance_scale],
56
+ outputs=output_image
57
+ )
58
+
59
+ gr.Markdown("---")
60
+ gr.Markdown("⚠️ **Hinweis:** Da dies auf einer CPU läuft, kann die Generierung 1-2 Minuten dauern.")
61
+
62
+ if __name__ == "__main__":
63
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ diffusers
4
+ transformers
5
+ accelerate
🎨 Uncensored AI Image Generator (CPU-Optimized).md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Uncensored AI Image Generator (CPU)
3
+ emoji: 🎨
4
+ colorFrom: pink
5
+ colorTo: purple
6
+ sdk: gradio
7
+ python_version: 3.9
8
+ app_file: app.py
9
+ ---
10
+
11
+ # 🎨 Uncensored AI Image Generator (CPU-Optimized)
12
+
13
+ This Gradio app allows generating images from text prompts using an uncensored Stable Diffusion model, optimized to run on CPU.
14
+
15
+ ## 🚀 Model
16
+
17
+ The app uses the `Kernel/sd-nsfw` model from Hugging Face. This is a Stable Diffusion v1-5 NSFW REALISM model designed for photorealistic image generation. To ensure compatibility with CPU hardware and optimize generation speed, the model is loaded with `torch_dtype=torch.float32` and moved to the CPU (`.to("cpu")`). The built-in safety checker has been disabled to allow for uncensored image generation.
18
+
19
+ ## ✨ Features
20
+
21
+ * **Text-to-Image Generation:** Create images from any text description.
22
+ * **Negative Prompt:** Specify what you do *not* want to see in the generated image to improve quality (e.g., "low quality, blurry, distorted").
23
+ * **Customizable Parameters:** Control the number of inference steps and the guidance scale for finer results.
24
+ * **CPU-Optimized:** Designed to work without a dedicated GPU, making it ideal for Hugging Face Spaces with CPU resources.
25
+
26
+ ## ⚙️ Local Installation & Usage
27
+
28
+ To run this app locally, follow these steps:
29
+
30
+ 1. **Clone the repository:**
31
+ ```bash
32
+ git clone https://github.com/YourUsername/YourRepoName
33
+ cd YourRepoName
34
+ ```
35
+ *(Note: This step is not necessary for Hugging Face Spaces, as you will upload the files directly.)*
36
+
37
+ 2. **Create a virtual environment (optional but recommended):**
38
+ ```bash
39
+ python3 -m venv venv
40
+ source venv/bin/activate
41
+ ```
42
+
43
+ 3. **Install dependencies:**
44
+ ```bash
45
+ pip install -r requirements.txt
46
+ ```
47
+
48
+ 4. **Run the app:**
49
+ ```bash
50
+ python app.py
51
+ ```
52
+
53
+ The app will then be available in your browser at `http://127.0.0.1:7860/` (or a similar port).
54
+
55
+ ## ☁️ Deployment on Hugging Face Spaces
56
+
57
+ To deploy this app on Hugging Face Spaces, create a new Space and upload the `app.py`, `requirements.txt`, and `README.md` files. Make sure to select `Gradio` as the SDK and set the Python version to `3.9` or higher.
58
+
59
+ ## ⚠️ Important Performance Note
60
+
61
+ Since this app runs on a CPU, image generation can take **1-2 minutes or longer**, especially with a higher number of inference steps. Please be patient. For faster generation, using GPU-accelerated models is recommended.
62
+
63
+ ## 📜 License
64
+
65
+ The `Kernel/sd-nsfw` model is licensed under the [CreativeML OpenRAIL M License](https://huggingface.co/spaces/CompVis/stable-diffusion-license).
66
+
67
+ ---