apolinario commited on
Commit
86a76f5
·
1 Parent(s): c38543f

Initial version

Browse files
Files changed (2) hide show
  1. app.py +33 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import LatentDiffusionPipeline
2
+ import gradio as gr
3
+ import PIL.Image
4
+ import numpy as np
5
+ import random
6
+ import torch
7
+
8
+ ldm_pipeline = LatentDiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")
9
+ images = []
10
+
11
+ def predict(prompt, steps=100, seed=42, guidance_scale=5.0):
12
+ torch.cuda.empty_cache()
13
+ generator = torch.manual_seed(seed)
14
+ image = ldm_pipeline([prompt], generator=generator, num_inference_steps=steps, guidance_scale=guidance_scale)
15
+ image_processed = image.cpu().permute(0, 2, 3, 1)
16
+ image_processed = (image_processed + 1.0) * 127.5
17
+ image_processed = image_processed.clamp(0, 255).numpy().astype(np.uint8)
18
+ return PIL.Image.fromarray(image_processed[0])
19
+
20
+ random_seed = random.randint(0, 2147483647)
21
+ gr.Interface(
22
+ predict,
23
+ inputs=[
24
+ gr.inputs.Textbox(label='Prompt', default='a chalk pastel drawing of a llama wearing a wizard hat'),
25
+ gr.inputs.Slider(1, 100, label='Inference Steps', default=50, step=1),
26
+ gr.inputs.Slider(0, 2147483647, label='Seed', default=random_seed, step=1),
27
+ gr.inputs.Slider(1.0, 20.0, label='Guidance Scale - how much the prompt will influence the results', default=5.0, step=0.1),
28
+ ],
29
+ outputs=gr.Image(shape=[256,256], type="pil", elem_id="output_image"),
30
+ css="#output_image{width: 256px}",
31
+ title="ldm-text2im-large-256 - 🧨 diffusers library",
32
+ description="This Spaces contains a text-to-image Latent Diffusion process for the <a href=\"https://huggingface.co/CompVis/ldm-text2im-large-256\">ldm-text2im-large-256</a> model by <a href=\"https://huggingface.co/CompVis\">CompVis</a> using the <a href=\"https://github.com/huggingface/diffusers\">diffusers library</a>. The goal of this demo is to showcase the diffusers library and you can check how the code works here. If you want the state-of-the-art experience with Latent Diffusion text-to-image check out the <a href=\"https://huggingface.co/spaces/multimodalart/latentdiffusion\">main Spaces</a>.",
33
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/huggingface/diffusers.git