import gradio as gr import replicate import random import os def query(prompt, aspect_ratio="1:1", steps=28, cfg_scale=3.5, seed=-1, strength=0.95): if seed == -1: seed = random.randint(1, 1000000000) input = { "prompt": prompt, "hf_lora": "codermert/mert_flux", "output_format": "jpg", "aspect_ratio": aspect_ratio, "num_inference_steps": steps, "guidance_scale": cfg_scale, "lora_scale": strength, "seed": seed, "disable_safety_checker": True } output = replicate.run( "lucataco/flux-dev-lora:a22c463f11808638ad5e2ebd582e07a469031f48dd567366fb4c6fdab91d614d", input=input ) print(output) return output[0], seed css = """ #app-container { max-width: 600px; margin-left: auto; margin-right: auto; } """ examples = [ "A beautiful landscape with mountains and a lake", "A futuristic cityscape at night", "A portrait of a smiling person in a colorful outfit", ] with gr.Blocks(theme='default', css=css) as app: gr.HTML("

Mert Flux Image Generator

") with gr.Column(elem_id="app-container"): with gr.Row(): text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2) with gr.Row(): with gr.Accordion("Advanced Settings", open=False): aspect_ratio = gr.Radio(label="Aspect ratio", value="1:1", choices=["1:1", "4:5", "2:3", "3:4","9:16", "4:3", "16:9"]) steps = gr.Slider(label="Sampling steps", value=28, minimum=1, maximum=100, step=1) cfg = gr.Slider(label="CFG Scale", value=3.5, minimum=1, maximum=20, step=0.5) strength = gr.Slider(label="Strength", value=0.95, minimum=0, maximum=1, step=0.001) seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1) with gr.Row(): text_button = gr.Button("Generate", variant='primary') with gr.Row(): image_output = gr.Image(type="pil", label="Generated Image", show_download_button=True) with gr.Row(): seed_output = gr.Textbox(label="Seed Used", show_copy_button=True) gr.Examples(examples=examples, inputs=[text_prompt]) text_button.click( query, inputs=[text_prompt, aspect_ratio, steps, cfg, seed, strength], outputs=[image_output, seed_output] ) app.launch(show_api=False)