Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4",
|
| 6 |
+
torch_dtype=torch.float16,
|
| 7 |
+
revision="fp16")
|
| 8 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
+
|
| 10 |
+
def genera_imatge(text):
|
| 11 |
+
imatge = pipe(text).images[0]
|
| 12 |
+
return imatge
|
| 13 |
+
|
| 14 |
+
demo = gr.Interface(fn=genera_imatge,
|
| 15 |
+
inputs="text",
|
| 16 |
+
outputs="image",
|
| 17 |
+
title="Generador d’Imatges")
|
| 18 |
+
|
| 19 |
+
demo.launch()
|