File size: 1,442 Bytes
17b362e
 
12f1129
 
17b362e
12f1129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch
from torchvision import transforms
from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")

# Define the starter and end prompts
starter_prompt = "Create a detailed sketch of a person based on the following description: "
end_prompt = " The sketch should have a monochromatic style, resembling a police mugshot, with clear outlines and shading to emphasize facial features. The background should be plain to focus on the subject."

# Function to generate the sketch
def generate_sketch(main_prompt):
    prompt = starter_prompt + main_prompt + end_prompt
    generator = torch.Generator("cpu").manual_seed(17)  # Use CPU for generation
    image = pipe(prompt, num_inference_steps=60, generator=generator).images[0]
    
    # Save the generated image (optional)
    image.save("testing.png")
    
    return image

# Create Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# InkScribe")
    main_prompt_input = gr.Textbox(label="Enter Description", placeholder="e.g., A young woman with curly black hair and green eyes, looking directly at the viewer.")
    generate_button = gr.Button("Generate Sketch")
    output_image = gr.Image(label="Generated Sketch", width= 512, height= 512)

    # Set up event handling
    generate_button.click(generate_sketch, inputs=main_prompt_input, outputs=output_image)

# Launch the app
demo.launch()