Spaces:
Runtime error
Runtime error
YongLD
commited on
Commit
·
e5f2ff8
1
Parent(s):
9b46133
Add application files
Browse files- app.py +30 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from diffusers import LDMTextToImagePipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import PIL.Image
|
| 5 |
+
import numpy as np
|
| 6 |
+
import random
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
ldm_pipeline = LDMTextToImagePipeline.from_pretrained("dalle-mini/dalle-mega")
|
| 10 |
+
|
| 11 |
+
def predict(prompt, steps=100, seed=42, guidance_scale=6.0):
|
| 12 |
+
torch.cuda.empty_cache()
|
| 13 |
+
generator = torch.manual_seed(seed)
|
| 14 |
+
images = ldm_pipeline([prompt], generator=generator, num_inference_steps=steps, eta=0.3, guidance_scale=guidance_scale)["sample"]
|
| 15 |
+
return images[0]
|
| 16 |
+
|
| 17 |
+
random_seed = random.randint(0, 2147483647)
|
| 18 |
+
gr.Interface(
|
| 19 |
+
predict,
|
| 20 |
+
inputs=[
|
| 21 |
+
gr.inputs.Textbox(label='Prompt', default='a chalk pastel drawing of a llama wearing a wizard hat'),
|
| 22 |
+
gr.inputs.Slider(1, 100, label='Inference Steps', default=50, step=1),
|
| 23 |
+
gr.inputs.Slider(0, 2147483647, label='Seed', default=random_seed, step=1),
|
| 24 |
+
gr.inputs.Slider(1.0, 20.0, label='Guidance Scale - how much the prompt will influence the results', default=6.0, step=0.1),
|
| 25 |
+
],
|
| 26 |
+
outputs=gr.Image(shape=[256,256], type="pil", elem_id="output_image"),
|
| 27 |
+
css="#output_image{width: 256px}",
|
| 28 |
+
title="Text-To-Image - 🧨 diffusers library",
|
| 29 |
+
description="This Spaces contains a text-to-image Latent Diffusion process for the <a href=\"https://huggingface.co/spaces/LDY/TextToImage\">main Spaces</a>.",
|
| 30 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diffusers==0.1.1
|
| 2 |
+
transformers
|