File size: 2,154 Bytes
fa2ca72
 
 
ac9a931
 
 
fa2ca72
ebf2699
 
 
 
 
 
 
 
 
 
 
 
 
fa2ca72
 
 
3bcc82e
fa2ca72
 
 
 
 
3bcc82e
fa2ca72
 
 
 
 
3bcc82e
ac9a931
 
 
 
 
 
fa2ca72
ebf2699
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa2ca72
ebf2699
 
 
 
 
 
fa2ca72
ebf2699
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
79
80
81
82
83
84
85
86
import gradio as gr
import replicate
import os
import requests
from PIL import Image
from io import BytesIO

examples = [
    "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
    "An astronaut riding a green horse",
    "A delicious ceviche cheesecake slice",
]

css="""
#col-container {
    margin: 0 auto;
    max-width: 640px;
}
"""

def generate_image(prompt, api_key):
    # Set the API key for the current session
    os.environ["REPLICATE_API_TOKEN"] = api_key
    
    # Prepare the input for the model
    inputs = {
        "prompt": prompt,
        "prompt_upsampling": True
    }
    
    # Run the model and get the output URL
    output_url = replicate.run(
        "black-forest-labs/flux-1.1-pro",
        input=inputs
    )
    
    # Fetch the image from the URL
    response = requests.get(output_url)
    image = Image.open(BytesIO(response.content))
    
    # Return the image
    return image


with gr.Blocks(css=css) as demo:
    
    with gr.Column(elem_id="col-container"):
        gr.Markdown(f"""
        # FLUX 1.1 Pro Text-to-Image Generator
        """)
        
        with gr.Row():
            with gr.Column():
                api_key = gr.Text(
                    label="Replicate API Key",
                    show_label=False,
                    max_lines=1,
                    placeholder="Enter your Replicate API key...",
                    container=False,
                    type="password",
                )
                prompt = gr.Text(
                    label="Prompt",
                    show_label=False,
                    max_lines=1,
                    placeholder="Enter your prompt",
                    container=False,
                )
            
            run_button = gr.Button("Run", scale=0)
        
        result = gr.Image(label="Result", show_label=False)

        
        gr.Examples(
            examples = examples,
            inputs = [prompt]
        )
    gr.on(
        triggers=[run_button.click, prompt.submit],
        fn = generate_image,
        inputs = [prompt, api_key],
        outputs = [result,]
    )

demo.queue().launch()