File size: 2,752 Bytes
8166181
 
 
 
 
 
 
 
 
 
 
 
 
 
eea1716
8166181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9929c16
ec41dba
 
 
535fa30
ec41dba
 
 
 
 
 
 
 
 
8166181
 
 
9929c16
 
535fa30
8166181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import spaces
from diffusers import AuraFlowPipeline
import torch
import gradio as gr

def initialize_auraflow_pipeline():
    """Initialize and return the AuraFlowPipeline."""
    pipeline = AuraFlowPipeline.from_pretrained(
        "fal/AuraFlow-v0.3",
        torch_dtype=torch.float16,
        variant="fp16",
    ).to("cuda")
    return pipeline

@spaces.GPU(duration=95)
def generate_image(pipeline, prompt, width, height, num_inference_steps, seed, guidance_scale):
    """Generate an image using the AuraFlowPipeline."""
    generator = torch.Generator().manual_seed(seed)

    image = pipeline(
        prompt=prompt,
        width=width,
        height=height,
        num_inference_steps=num_inference_steps,
        generator=generator,
        guidance_scale=guidance_scale,
    ).images[0]

    return image

# Initialize the pipeline once
auraflow_pipeline = initialize_auraflow_pipeline()

# Gradio interface
def gradio_generate_image(prompt, width, height, num_inference_steps, seed, guidance_scale):
    return generate_image(auraflow_pipeline, prompt, width, height, num_inference_steps, seed, guidance_scale)

# Create Gradio Blocks
with gr.Blocks(theme="bethecloud/storj_theme") as demo:
    gr.HTML(
        """
    <h1 style='text-align: center'>
    AuraFlow v0.3
    </h1>
    """)
    gr.HTML(
        """
        <h3 style='text-align: center'>
        Follow me for more!
        <a href='https://twitter.com/kadirnar_ai' target='_blank'>Twitter</a> | <a href='https://github.com/kadirnar' target='_blank'>Github</a> | <a href='https://www.linkedin.com/in/kadir-nar/' target='_blank'>Linkedin</a>  | <a href='https://www.huggingface.co/kadirnar/' target='_blank'>HuggingFace</a>
        </h3>
        """)
    with gr.Row():
        with gr.Column():
            prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your image prompt here...")
            width_input = gr.Slider(minimum=256, maximum=1536, step=64, value=1024, label="Width")
            height_input = gr.Slider(minimum=256, maximum=1536, step=64, value=1024, label="Height")
            steps_input = gr.Slider(minimum=10, maximum=100, step=1, value=20, label="Number of Inference Steps")
            seed_input = gr.Number(label="Seed", value=1)
            guidance_input = gr.Slider(minimum=1, maximum=10, step=0.1, value=3.5, label="Guidance Scale")
            generate_btn = gr.Button("Generate Image")
        
        with gr.Column():
            image_output = gr.Image(label="Generated Image")
    
    generate_btn.click(
        fn=gradio_generate_image,
        inputs=[prompt_input, width_input, height_input, steps_input, seed_input, guidance_input],
        outputs=image_output
    )

# Launch the Gradio interface
demo.launch()