Spaces:
Runtime error
Runtime error
File size: 1,905 Bytes
e65d65f |
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 PIL import Image
from models import LineartGenerator
class SketchToImageApp:
"""
An application that combines a user’s annotated sketch with original lineart,
and then generates an image using a ControlNet-based pipeline.
"""
def __init__(self, lineart_generator: LineartGenerator):
self.lineart_generator = lineart_generator
def generate_image(self, brush_canvas: dict, uploaded_file) -> Image.Image:
merged_lineart = self.lineart_generator.merge_lineart_and_brush(brush_canvas, uploaded_file)
return self.lineart_generator.generate_image(merged_lineart, num_inference_steps=30)
def create_interface(self) -> gr.Blocks:
with gr.Blocks() as app:
gr.Markdown(
"# Lineart & Color Mask With Controlnet\n"
"Brush strokes will be applied behind the processed lineart so that the "
"black lines always remain visible."
)
lineart_file_input = gr.File(
label="Upload Lineart Sketch",
file_types=["image"],
file_count="single"
)
with gr.Row():
brush_canvas_input = gr.Sketchpad(
label="Annotate Your Lineart",
type="numpy",
brush=gr.Brush(),
)
lineart_file_input.change(
fn=self.lineart_generator.load_lineart_image,
inputs=lineart_file_input,
outputs=brush_canvas_input
)
generate_button = gr.Button("Generate")
output_image = gr.Image(label="Generated Image")
generate_button.click(
fn=self.generate_image,
inputs=[brush_canvas_input, lineart_file_input],
outputs=output_image
)
return app
|