cforge42 commited on
Commit
290406f
·
verified ·
1 Parent(s): e7b9a38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,13 +1,19 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Load the BigGAN model using the transformers pipeline
5
- generator = pipeline("text-to-image", model="osanseviero/BigGAN-deep-128")
 
 
 
 
 
6
 
7
  def generate_image(text_input):
8
- """Generates an image from text using the BigGAN pipeline."""
9
  # The pipeline's output is an image.
10
- image = generator(text_input)["images"][0]
11
  return image
12
 
13
  # Create the Gradio interface directly
 
1
  import gradio as gr
2
+ import torch
3
+ from diffusers import DiffusionPipeline
4
 
5
+ # Load the BigGAN model using the diffusers library
6
+ # The model type is "biggan", which is the correct pipeline to use.
7
+ # Move model to GPU if available for faster generation
8
+ pipeline = DiffusionPipeline.from_pretrained(
9
+ "osanseviero/BigGAN-deep-128",
10
+ use_auth_token=True
11
+ ).to("cuda" if torch.cuda.is_available() else "cpu")
12
 
13
  def generate_image(text_input):
14
+ """Generates an image from text using the BigGAN diffusers pipeline."""
15
  # The pipeline's output is an image.
16
+ image = pipeline(text_input).images[0]
17
  return image
18
 
19
  # Create the Gradio interface directly