Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +61 -0
- requirements.txt +8 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import StableDiffusionXLPipeline
|
| 2 |
+
import torch
|
| 3 |
+
from transformers.pipelines.image_to_text import Image
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 7 |
+
"segmind/SSD-1B",
|
| 8 |
+
torch_dtype = torch.float16,
|
| 9 |
+
use_safetensors=True,
|
| 10 |
+
variant = "fp16",
|
| 11 |
+
)
|
| 12 |
+
pipe.to("cuda")
|
| 13 |
+
|
| 14 |
+
prompt = "astronaut riding a green horse"
|
| 15 |
+
neg_prompt = "ugly, blurry, poor quality"
|
| 16 |
+
|
| 17 |
+
def generate_image(prompt, neg_prompt):
|
| 18 |
+
image = pipe(
|
| 19 |
+
prompt=prompt,
|
| 20 |
+
negative_prompt=neg_prompt
|
| 21 |
+
).images[0]
|
| 22 |
+
return image
|
| 23 |
+
|
| 24 |
+
prompt = gr.Text(
|
| 25 |
+
label="Prompt",
|
| 26 |
+
show_label=False,
|
| 27 |
+
max_lines=1,
|
| 28 |
+
placeholder="Enter your prompt :",
|
| 29 |
+
container=False
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
neg_prompt = gr.Text(
|
| 33 |
+
label="Negative Prompt",
|
| 34 |
+
show_label=False,
|
| 35 |
+
max_lines=1,
|
| 36 |
+
placeholder="Enter your negative prompt",
|
| 37 |
+
container=False
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
iface = gr.Interface(
|
| 41 |
+
fn=generate_image,
|
| 42 |
+
inputs=[prompt, neg_prompt],
|
| 43 |
+
outputs="image",
|
| 44 |
+
title="Text to Image Generation",
|
| 45 |
+
examples=[
|
| 46 |
+
["a painting of a cute cat sitting on a chair","ugly, blurry"],
|
| 47 |
+
["an assortment riding a horse on mars","poorly down"]
|
| 48 |
+
],
|
| 49 |
+
allow_flagging=False
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
iface.launch(share=True)
|
| 53 |
+
#image = pipe(prompt=prompt, negative_prompt = neg_prompt).images[0]
|
| 54 |
+
# print(image)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
git+https://github.com/huggingface/diffusers
|
| 2 |
+
transformers
|
| 3 |
+
accelerate
|
| 4 |
+
safetensors
|
| 5 |
+
gradio
|
| 6 |
+
torch
|
| 7 |
+
|
| 8 |
+
|