Spaces:
Running
on
Zero
Running
on
Zero
File size: 2,496 Bytes
0aeab2f e383bbb 0aeab2f e383bbb 0aeab2f e383bbb 0aeab2f |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# import gradio as gr
# import torch
# from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
# from PIL import Image
# import base64
# from io import BytesIO
# # You can change these:
# BASE_MODEL = "runwayml/stable-diffusion-v1-5"
# CONTROLNET_ID = "lllyasviel/sd-controlnet-canny" # placeholder; change to a QR-focused ControlNet if you have one
# device = "cuda" if torch.cuda.is_available() else "cpu"
# controlnet = ControlNetModel.from_pretrained(
# CONTROLNET_ID, torch_dtype=torch.float16 if device=="cuda" else torch.float32
# )
# pipe = StableDiffusionControlNetPipeline.from_pretrained(
# BASE_MODEL,
# controlnet=controlnet,
# torch_dtype=torch.float16 if device=="cuda" else torch.float32,
# safety_checker=None
# )
# pipe.to(device)
# def generate(prompt, control_image, guidance_scale=7.5, steps=30, seed=0):
# generator = torch.Generator(device=device).manual_seed(int(seed)) if seed else None
# img = pipe(
# prompt=prompt,
# image=control_image,
# num_inference_steps=int(steps),
# guidance_scale=float(guidance_scale),
# generator=generator
# ).images[0]
# return img
# with gr.Blocks() as demo:
# gr.Markdown("# ControlNet Image Generator")
# with gr.Row():
# prompt = gr.Textbox(label="Prompt", value="A futuristic poster, high detail")
# seed = gr.Number(label="Seed (0=random)", value=0)
# with gr.Row():
# control = gr.Image(type="pil", label="Control image (e.g., QR or edge map)")
# steps = gr.Slider(10, 50, 30, step=1, label="Steps")
# guidance = gr.Slider(1.0, 12.0, 7.5, step=0.1, label="Guidance scale")
# out = gr.Image(label="Result")
# btn = gr.Button("Generate")
# btn.click(generate, [prompt, control, guidance, steps, seed], out)
# # Enable simple API use
# gr.Examples([], inputs=[prompt, control, guidance, steps, seed], outputs=out)
# demo.launch()
import gradio as gr
from PIL import Image
def generate(prompt, control_image, guidance, steps, seed):
# dummy return so Space builds
return control_image
demo = gr.Interface(
fn=generate,
inputs=[
gr.Textbox(label="Prompt"),
gr.Image(type="pil", label="Control Image"),
gr.Slider(1, 12, 7.5, label="Guidance scale"),
gr.Slider(10, 50, 30, step=1, label="Steps"),
gr.Number(0, label="Seed"),
],
outputs=gr.Image(),
)
if __name__ == "__main__":
demo.launch()
|