Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
demo.launch()
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Basismodell laden
|
| 6 |
+
base_model = "runwayml/stable-diffusion-v1-5"
|
| 7 |
+
pipe = StableDiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.float16).to("cuda")
|
| 8 |
+
|
| 9 |
+
# Optional: NSFW-Filter deaktivieren
|
| 10 |
+
pipe.safety_checker = lambda images, **kwargs: (images, False)
|
| 11 |
+
|
| 12 |
+
# LoRA laden (Beispiel: LoRA-Dateien lokal gespeichert)
|
| 13 |
+
pipe.load_lora_weights("path/to/lora_weights")
|
| 14 |
+
|
| 15 |
+
# LoRA aktivieren (nur nötig bei manchen Implementierungen)
|
| 16 |
+
pipe.fuse_lora()
|
| 17 |
+
|
| 18 |
+
def generate(prompt):
|
| 19 |
+
image = pipe(prompt).images[0]
|
| 20 |
+
return image
|
| 21 |
+
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
with gr.Row():
|
| 24 |
+
gr.Markdown("## NSFW Uncensored + LoRA Stable Diffusion")
|
| 25 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Eingabe z.B. 'a nude portrait in oil painting style'")
|
| 26 |
+
output = gr.Image()
|
| 27 |
+
btn = gr.Button("Generate")
|
| 28 |
+
|
| 29 |
+
btn.click(fn=generate, inputs=prompt, outputs=output)
|
| 30 |
+
|
| 31 |
demo.launch()
|