AP123 commited on
Commit
42a1e5c
·
verified ·
1 Parent(s): a826a95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -2,11 +2,10 @@ import gradio as gr
2
  import torch
3
  from PIL import Image
4
  from diffusers import AutoPipelineForText2Image, DDIMScheduler
5
- from transformers import CLIPVisionModelWithProjection
6
  import numpy as np
7
  import spaces # Make sure to import spaces
8
 
9
- # Initialize the pipeline without specifying the device; this will be handled by the @spaces.GPU decorator
10
  pipeline = AutoPipelineForText2Image.from_pretrained(
11
  "stabilityai/stable-diffusion-xl-base-1.0",
12
  torch_dtype=torch.float16
@@ -26,14 +25,13 @@ pipeline.load_ip_adapter(
26
  )
27
  pipeline.set_ip_adapter_scale([0.7, 0.5])
28
 
29
- # Ensure the model and its components are moved to GPU
30
- pipeline.to("cuda")
31
-
32
- # Define the desired size
33
  desired_size = (1024, 1024)
34
 
35
  @spaces.GPU
36
  def transform_image(face_image):
 
 
37
  generator = torch.Generator(device="cuda").manual_seed(0)
38
 
39
  # Process the input face image
@@ -60,7 +58,7 @@ def transform_image(face_image):
60
  generator=generator,
61
  ).images[0]
62
 
63
- # Move the pipeline back to CPU after processing to release GPU resources
64
  pipeline.to("cpu")
65
  return image
66
 
@@ -70,7 +68,7 @@ demo = gr.Interface(
70
  inputs=gr.Image(label="Upload your face image"),
71
  outputs=gr.Image(label="Your Soyjak"),
72
  title="InstaSoyjak - turn anyone into a Soyjak",
73
- description="All you need to do is upload an image. Please use responsibly. Please follow me on Twitter if you like this space: https://twitter.com/angrypenguinPNG. Idea from Yacine, please give him a follow: https://twitter.com/yacineMTB.",
74
  )
75
 
76
  demo.queue(max_size=20)
 
2
  import torch
3
  from PIL import Image
4
  from diffusers import AutoPipelineForText2Image, DDIMScheduler
 
5
  import numpy as np
6
  import spaces # Make sure to import spaces
7
 
8
+ # Initialize the pipeline
9
  pipeline = AutoPipelineForText2Image.from_pretrained(
10
  "stabilityai/stable-diffusion-xl-base-1.0",
11
  torch_dtype=torch.float16
 
25
  )
26
  pipeline.set_ip_adapter_scale([0.7, 0.5])
27
 
28
+ # Define the desired size for the images
 
 
 
29
  desired_size = (1024, 1024)
30
 
31
  @spaces.GPU
32
  def transform_image(face_image):
33
+ # Move the pipeline to the GPU inside the function
34
+ pipeline.to("cuda")
35
  generator = torch.Generator(device="cuda").manual_seed(0)
36
 
37
  # Process the input face image
 
58
  generator=generator,
59
  ).images[0]
60
 
61
+ # Move the pipeline back to CPU after processing if necessary
62
  pipeline.to("cpu")
63
  return image
64
 
 
68
  inputs=gr.Image(label="Upload your face image"),
69
  outputs=gr.Image(label="Your Soyjak"),
70
  title="InstaSoyjak - turn anyone into a Soyjak",
71
+ description="All you need to do is upload an image. Please use responsibly.",
72
  )
73
 
74
  demo.queue(max_size=20)