Spaces:
Sleeping
Sleeping
File size: 1,896 Bytes
cbf3b43 6ffa0fc cbf3b43 6ffa0fc cbf3b43 6ffa0fc cbf3b43 6ffa0fc cbf3b43 6ffa0fc cbf3b43 6ffa0fc cbf3b43 6ffa0fc cbf3b43 6ffa0fc cbf3b43 6ffa0fc | 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 47 48 49 50 51 52 53 54 55 56 | import gradio as gr
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
import torch
import os
# --- Configuration ---
MODEL_ID = "benisonjac/stable-diffusion-finetune"
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
DTYPE = torch.float16 if torch.cuda.is_available() else torch.float32
# --- Load a new, more stable scheduler from the model's config ---
scheduler = DPMSolverMultistepScheduler.from_pretrained(MODEL_ID, subfolder="scheduler")
# --- Load the Pipeline ---
print(f"Loading full fine-tuned model from {MODEL_ID}...")
# Load the entire pipeline from your repository and inject the new scheduler
pipe = DiffusionPipeline.from_pretrained(
MODEL_ID,
torch_dtype=DTYPE,
scheduler=scheduler,
).to(DEVICE)
print("Model loaded successfully.")
pipe.unet.eval()
# --- Define the Generation Function ---
def generate(prompt, guidance_scale=7.5, num_steps=50):
with torch.no_grad():
image = pipe(
prompt,
guidance_scale=guidance_scale,
num_inference_steps=int(num_steps)
).images[0]
return image
# --- Create the Gradio Interface ---
demo = gr.Interface(
fn=generate,
inputs=[
gr.Textbox(label="Prompt", value="a photo of a high-top sneaker, futuristic design"),
gr.Slider(minimum=1, maximum=20, step=0.5, value=7.5, label="Guidance Scale"),
gr.Slider(minimum=10, maximum=100, step=1, value=50, label="Inference Steps")
],
outputs=gr.Image(type="pil"),
title="Generative AI Shoe Generator",
description="Enter a prompt to generate a unique shoe design using a fully fine-tuned Stable Diffusion model.",
allow_flagging="never",
examples=[
["a photo of a running shoe, vibrant colors", 7.5, 50],
["a photo of a leather boot, classic style", 8.0, 60],
]
)
# --- Launch the App ---
demo.launch(share=True, debug=True) |