Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
from diffusers import
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
-
|
9 |
-
image_style = "pixel art"
|
10 |
torch_dtype = torch.float32
|
11 |
|
12 |
if torch.cuda.is_available():
|
@@ -17,20 +16,18 @@ def generate_description(image):
|
|
17 |
return model(image)[0]['generated_text']
|
18 |
|
19 |
def generate_image_by_description(description):
|
20 |
-
pipe =
|
21 |
pipe = pipe.to(device)
|
|
|
|
|
22 |
prompt = (
|
23 |
-
f"Generate a
|
24 |
f"The description of the pigeon is: {description}. "
|
25 |
-
|
26 |
-
)
|
27 |
-
image = pipe(
|
28 |
-
prompt,
|
29 |
-
num_inference_steps=40,
|
30 |
-
guidance_scale=4.5,
|
31 |
-
).images[0]
|
32 |
return image
|
33 |
|
|
|
34 |
with gr.Blocks() as demo:
|
35 |
selected_image = gr.Image(type="filepath", label="Upload an Image of the Pigeon")
|
36 |
generate_button = gr.Button("Generate Avatar", variant="primary")
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
|
|
9 |
torch_dtype = torch.float32
|
10 |
|
11 |
if torch.cuda.is_available():
|
|
|
16 |
return model(image)[0]['generated_text']
|
17 |
|
18 |
def generate_image_by_description(description):
|
19 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch_dtype)
|
20 |
pipe = pipe.to(device)
|
21 |
+
pipe.enable_attention_slicing()
|
22 |
+
|
23 |
prompt = (
|
24 |
+
f"Generate a image of a pigeon for my profile avatar. "
|
25 |
f"The description of the pigeon is: {description}. "
|
26 |
+
)
|
27 |
+
image = pipe(prompt).images[0]
|
|
|
|
|
|
|
|
|
|
|
28 |
return image
|
29 |
|
30 |
+
|
31 |
with gr.Blocks() as demo:
|
32 |
selected_image = gr.Image(type="filepath", label="Upload an Image of the Pigeon")
|
33 |
generate_button = gr.Button("Generate Avatar", variant="primary")
|