File size: 941 Bytes
73f13a5
3e255ae
0f33d77
 
c286aff
73f13a5
 
 
 
 
 
 
 
c286aff
73f13a5
211b07f
73f13a5
 
211b07f
3e255ae
211b07f
 
 
73f13a5
 
211b07f
3e255ae
73f13a5
cf061d9
dee565e
211b07f
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
import gradio as gr
import os
import torch
from diffusers import DiffusionPipeline

# Load Hugging Face access token from secrets
hf_token = os.getenv("secret")  # Ensure your secret is named "secret"

# Set up the pipeline with the access token
pipeline = DiffusionPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev",
    use_auth_token=hf_token
).to("cuda" if torch.cuda.is_available() else "cpu")

# Inference function
def generate_image(prompt):
    with torch.no_grad():
        image = pipeline(prompt).images[0]
    return image

# Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# FLUX Image Generator")
    prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g. Astronaut riding a horse")
    generate_btn = gr.Button("Generate Image")
    output_image = gr.Image(label="Generated Image")

    generate_btn.click(fn=generate_image, inputs=prompt, outputs=output_image)

# Launch the app
demo.launch()