Update app.py
Browse files
app.py
CHANGED
|
@@ -2,21 +2,18 @@ import gradio as gr
|
|
| 2 |
from diffusers import DiffusionPipeline
|
| 3 |
import torch
|
| 4 |
#für die komplexere Variante der Erzeugung
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
#######################################
|
| 16 |
#Bild nach dem eingegebenen prompt erzeugen - mit Pipeline
|
| 17 |
def erzeuge_1(prompt):
|
| 18 |
-
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2")
|
| 19 |
-
pipeline.to("cuda")
|
| 20 |
return pipeline(prompt).images[0]
|
| 21 |
|
| 22 |
########################################
|
|
@@ -41,7 +38,26 @@ def erzeuge(prompt):
|
|
| 41 |
image = Image.fromarray((image * 255).round().astype("uint8"))
|
| 42 |
return image
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
with gr.Column(variant="panel"):
|
| 47 |
with gr.Row(variant="compact"):
|
|
|
|
| 2 |
from diffusers import DiffusionPipeline
|
| 3 |
import torch
|
| 4 |
#für die komplexere Variante der Erzeugung
|
| 5 |
+
from diffusers import DDPMScheduler, UNet2DModel
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import numpy as np
|
| 8 |
|
| 9 |
|
| 10 |
+
##############################################
|
| 11 |
+
#Hilfsfunktionen
|
| 12 |
+
##############################################
|
|
|
|
| 13 |
|
| 14 |
#######################################
|
| 15 |
#Bild nach dem eingegebenen prompt erzeugen - mit Pipeline
|
| 16 |
def erzeuge_1(prompt):
|
|
|
|
|
|
|
| 17 |
return pipeline(prompt).images[0]
|
| 18 |
|
| 19 |
########################################
|
|
|
|
| 38 |
image = Image.fromarray((image * 255).round().astype("uint8"))
|
| 39 |
return image
|
| 40 |
|
| 41 |
+
######################################################
|
| 42 |
+
#Modelle laden
|
| 43 |
+
#######################################
|
| 44 |
+
#Alternativ erzeugen
|
| 45 |
+
#gr.Interface.load("models/stabilityai/stable-diffusion-2").launch()
|
| 46 |
+
|
| 47 |
+
#######################################
|
| 48 |
+
#Alternativ: Model über pipeline laden
|
| 49 |
+
#pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2")
|
| 50 |
+
#pipeline.to("cuda")
|
| 51 |
+
|
| 52 |
+
########################################
|
| 53 |
+
#Alternativ: Bild erzeugen - nicht über Pipeline sondern mit mehr Einstellungsmöglichkeiten
|
| 54 |
+
scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
|
| 55 |
+
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
|
| 56 |
+
|
| 57 |
|
| 58 |
+
######################################################
|
| 59 |
+
#Gradio UI erzeugen
|
| 60 |
+
######################################################
|
| 61 |
with gr.Blocks() as demo:
|
| 62 |
with gr.Column(variant="panel"):
|
| 63 |
with gr.Row(variant="compact"):
|