Spaces:
Sleeping
Sleeping
File size: 1,008 Bytes
f901652 b024062 f901652 b024062 |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import gradio as gr
import spaces
import torch
from diffusers import DiffusionPipeline
@spaces.GPU()
@torch.inference_mode()
def inference(
model_id: str,
prompt: str,
negative_prompt: str = "",
progress=gr.Progress(track_tqdm=True),
):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
pipe = DiffusionPipeline.from_pretrained(
model_id,
torch_dtype=torch.float16,
).to(device)
image = pipe(
prompt,
negative_prompt=negative_prompt,
).images[0]
return image
if __name__ == "__main__":
demo = gr.Interface(
fn=inference,
inputs=[
gr.Text(
label="Model ID",
value="stabilityai/stable-diffusion-3-medium-diffusers",
),
gr.Text(label="Prompt", value=""),
gr.Text(label="Negative Prompt", value=""),
],
outputs=[
gr.Image(label="Image", type="pil"),
],
)
demo.launch()
|