ItzRoBeerT commited on
Commit
88a3ed8
·
verified ·
1 Parent(s): b82e3f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -1,12 +1,11 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- from diffusers import StableDiffusion3Pipeline
4
  from diffusers import DiffusionPipeline
5
  import torch
6
 
7
  device = "cuda" if torch.cuda.is_available() else "cpu"
8
- model_repo_id = "stabilityai/stable-diffusion-3.5-medium"
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 = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
21
  pipe = pipe.to(device)
 
 
22
  prompt = (
23
- f"Generate a high-quality, detailed image of a {image_style} of a pigeon. "
24
  f"The description of the pigeon is: {description}. "
25
- "Make it visually appealing with clear textures and distinct colors."
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")