File size: 2,734 Bytes
09c04f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import gradio as gr
from gradio_client import Client

# Initialize the Hugging Face client with the specific model
client = Client("ByteDance/Hyper-FLUX-8Steps-LoRA")

def generate_image(prompt, height, width, steps, scale, seed):
    """
    Function to generate an image based on the provided prompt and parameters.
    
    Args:
        prompt (str): The text prompt to generate the image.
        height (int): The height of the generated image.
        width (int): The width of the generated image.
        steps (int): Number of inference steps.
        scale (float): Guidance scale for the image generation.
        seed (int): Seed for random number generator to ensure reproducibility.
    
    Returns:
        Image: Generated image based on the prompt and parameters.
    """
    try:
        # Call the predict method of the client with provided parameters
        result = client.predict(
            height=height,
            width=width,
            steps=steps,
            scales=scale,
            prompt=prompt,
            seed=seed,
            api_name="/process_image"
        )
        return result
    except Exception as e:
        return f"An error occurred: {e}"

# Define the input components
prompt_input = gr.inputs.Textbox(
    lines=2, 
    placeholder="Enter your prompt here...", 
    label="Prompt"
)

height_input = gr.inputs.Slider(
    minimum=256, 
    maximum=2048, 
    step=64, 
    default=1024, 
    label="Image Height"
)

width_input = gr.inputs.Slider(
    minimum=256, 
    maximum=2048, 
    step=64, 
    default=1024, 
    label="Image Width"
)

steps_input = gr.inputs.Slider(
    minimum=1, 
    maximum=50, 
    step=1, 
    default=8, 
    label="Inference Steps"
)

scale_input = gr.inputs.Slider(
    minimum=1.0, 
    maximum=10.0, 
    step=0.1, 
    default=3.5, 
    label="Guidance Scale"
)

seed_input = gr.inputs.Number(
    default=3413, 
    label="Seed", 
    precision=0
)

# Define the output component
image_output = gr.outputs.Image(label="Generated Image")

# Create the Gradio interface
iface = gr.Interface(
    fn=generate_image,
    inputs=[prompt_input, height_input, width_input, steps_input, scale_input, seed_input],
    outputs=image_output,
    title="Hyper-FLUX-8Steps-LoRA Image Generator",
    description="Generate images from text prompts using the Hyper-FLUX-8Steps-LoRA model.",
    examples=[
        ["A serene landscape with mountains and a river", 1024, 1024, 8, 3.5, 42],
        ["A futuristic city skyline at sunset", 1024, 1024, 8, 3.5, 1234],
        ["An abstract painting with vibrant colors", 1024, 1024, 8, 3.5, 5678],
    ],
    allow_flagging="never"
)

# Launch the interface
if __name__ == "__main__":
    iface.launch()