RAMYASRI-39's picture
Create app.py
09c04f2 verified
raw
history blame
2.73 kB
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()