File size: 1,493 Bytes
85b6abd
 
 
 
0672323
85b6abd
 
 
0672323
85b6abd
 
0672323
85b6abd
0672323
 
 
 
 
85b6abd
0672323
 
 
 
85b6abd
0672323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from diffusers import AutoPipelineForText2Image
import torch

# Load Dreambooth model
pipeline = AutoPipelineForText2Image.from_pretrained("sd-dreambooth-library/herge-style", torch_dtype=torch.float16).to("cuda")

def generate_image(prompt):
    # Generate image based on prompt
    pipeline.enable_freeu(s1=0.6, s2=0.4, b1=1.1, b2=1.2)
    image = pipeline(prompt).images[0]
    return image

def image_to_base64(image):
    # Convert image to base64
    buffered = BytesIO()
    image.save(buffered, format="JPEG")
    return base64.b64encode(buffered.getvalue()).decode()

def base64_to_image(base64_str):
    # Convert base64 to image
    image_data = base64.b64decode(base64_str)
    return Image.open(BytesIO(image_data))

def handle_prompt_image(prompt):
    # Generate image based on prompt and convert to base64
    image = generate_image(prompt)
    base64_str = image_to_base64(image)
    return base64_str

def main():
    # Interface setup
    image_input = gr.Textbox(label="Prompt", lines=3, placeholder="Enter your prompt here...")
    prompt_output = gr.Textbox(label="Base64 Encoded Image", readonly=True)

    iface = gr.Interface(
        fn=handle_prompt_image,
        inputs=image_input,
        outputs=prompt_output,
        title="Dreambooth Image Generator",
        description="Enter a prompt to generate an image using the Dreambooth model.",
        theme="compact"
    )

    iface.launch(share=True)

if __name__ == "__main__":
    main()