flux-schnell / app.py
Serg4451D's picture
Create app.py
89baeaf verified
raw
history blame
2.77 kB
import gradio as gr
from gradio_client import Client
import random
def generate_image(prompt, width, height, steps, seed_choice):
client = Client("black-forest-labs/FLUX.1-schnell")
# Определяем seed
if seed_choice == "Random":
seed = random.randint(0, 999999)
else:
seed = 0
result = client.predict(
prompt=prompt,
seed=seed,
randomize_seed=(seed_choice == "Random"),
width=width,
height=height,
num_inference_steps=steps,
api_name="/infer"
)
return result
# Создаем интерфейс
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown(
"""
# 🎨 AI Image Generator
Create amazing images using advanced AI technology!
"""
)
with gr.Row():
with gr.Column(scale=1):
# Inputs
prompt = gr.Textbox(
label="Prompt",
placeholder="Describe the image you want to generate...",
lines=3
)
with gr.Row():
width = gr.Slider(
minimum=512,
maximum=1024,
step=64,
value=1024,
label="Width"
)
height = gr.Slider(
minimum=512,
maximum=1024,
step=64,
value=1024,
label="Height"
)
steps = gr.Slider(
minimum=1,
maximum=50,
step=1,
value=4,
label="Inference Steps"
)
seed_choice = gr.Radio(
choices=["Fixed", "Random"],
value="Random",
label="Seed Type"
)
generate_btn = gr.Button(
"🎨 Generate",
variant="primary"
)
with gr.Column(scale=1):
# Output
output_image = gr.Image(
label="Generated Image",
type="filepath"
)
# События
generate_btn.click(
fn=generate_image,
inputs=[prompt, width, height, steps, seed_choice],
outputs=output_image
)
gr.Markdown(
"""
### Tips:
- Try different prompts to get various results
- Adjust width and height for different image sizes
- Increase steps for better quality (but slower generation)
- Use fixed seed to get reproducible results
"""
)
# Запускаем интерфейс
demo.launch()