File size: 3,173 Bytes
ed510c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from gradio_client import Client
import random

# Initialize the client for the Hugging Face Space
client = Client("ByteDance/Hyper-FLUX-8Steps-LoRA")

def generate_image(prompt, height, width, steps, scales, seed):
    """

    Generates an image based on the provided parameters by calling the Hugging Face Space API.



    Parameters:

    - prompt (str): The text prompt for image generation.

    - height (int): The height of the generated image.

    - width (int): The width of the generated image.

    - steps (int): The number of steps for the image generation process.

    - scales (float): The scaling factor.

    - seed (int): The seed for random number generation to ensure reproducibility.



    Returns:

    - result (str or Image): The generated image or a link to it.

    """
    # Generate a random seed if not provided
    if not seed:
        seed = random.randint(0, 100000)

    try:
        result = client.predict(
            height=int(height),
            width=int(width),
            steps=int(steps),
            scales=float(scales),
            prompt=prompt,
            seed=int(seed),
            api_name="/process_image"
        )
        return result
    except Exception as e:
        return f"An error occurred: {e}"

# Define the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Hyper-FLUX-8Steps-LoRA Image Generator")
    gr.Markdown("Generate images based on your text prompts using the Hyper-FLUX-8Steps-LoRA model.")

    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(
                label="Prompt",
                placeholder="Enter your descriptive text here...",
                lines=2
            )
            height = gr.Number(
                label="Height",
                value=1024,
                precision=0,
                interactive=True
            )
            width = gr.Number(
                label="Width",
                value=1024,
                precision=0,
                interactive=True
            )
            steps = gr.Number(
                label="Steps",
                value=8,
                precision=0,
                interactive=True
            )
            scales = gr.Number(
                label="Scale",
                value=3.5,
                precision=1,
                interactive=True
            )
            seed = gr.Number(
                label="Seed",
                value=3413,
                precision=0,
                interactive=True
            )
            generate_button = gr.Button("Generate Image")

        with gr.Column():
            output_image = gr.Image(label="Generated Image", interactive=False)

    # Define the button click action
    generate_button.click(
        fn=generate_image,
        inputs=[prompt, height, width, steps, scales, seed],
        outputs=output_image
    )

    # Optional: Add a footer or additional information
    gr.Markdown("© 2024 Your Name. All rights reserved.")

# Launch the Gradio app
if __name__ == "__main__":
    demo.launch()