File size: 968 Bytes
ab03ae0 290406f ae69d05 290406f e8cb6ca 4d7123e 290406f 4d7123e 290406f 4d7123e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import gradio as gr
import torch
from diffusers import DiffusionPipeline
# Load the BigGAN model using the diffusers library
# The model type is "biggan", which is the correct pipeline to use.
# Move model to GPU if available for faster generation
pipeline = DiffusionPipeline.from_pretrained(
"osanseviero/BigGAN-deep-128",
use_auth_token=True
).to("cuda" if torch.cuda.is_available() else "cpu")
def generate_image(text_input):
"""Generates an image from text using the BigGAN diffusers pipeline."""
# The pipeline's output is an image.
image = pipeline(text_input).images[0]
return image
# Create the Gradio interface directly
interface = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(label="Enter a prompt"),
outputs=gr.Image(label="Generated Image"),
title="BigGAN ImageNet",
description="BigGAN text-to-image demo.",
examples=[["american robin"], ["ocean sunset"], ["cat in a hat"]]
)
interface.launch()
|