| import gradio as gr |
| import requests |
| import io |
| import random |
| import os |
| import time |
| from PIL import Image |
| import json |
| import replicate |
|
|
| |
|
|
| |
| |
| |
| |
|
|
| 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/mert2_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 = [ |
| "KAMALINEE, A charismatic speaker is captured mid-speech. She has long, tousled brown hair that’s slightly messy on top. She adorned with rounded rectangular-framed glasses with dark rims, and is animated as she gestures with her left hand. She is holding a black microphone in her right hand, speaking passionately. The woman is wearing a light grey sweater over a white t-shirt. She’s also wearing a simple black lanyard hanging around her neck. The lanyard badge has the text “Kamalinee”. Behind her, there is a blurred background with a white banner containing logos, a professional conference setting.", |
| "KAMALINEE, An image of a woman. She dressed in a red and navy plaid shirt with the top unbuttoned to show a white undershirt, and the sleeves rolled up to the forearms. The woman is casually leaning against a weathered blue door frame with peeling paint, adding a rustic charm to the scene. Her arms are crossed or resting in front of her, and she has a soft, contemplative expression on her face.", |
| "Digital illustration style, realistic, drunk beautiful woman KAMALINEE, drinking whiskey, side view, short hair, glossy red lips, moist eyes, v-neck collared shirt, dingy outdoor restaurant background, moonlight, backlighting", |
| "an elegant and timeless portrait of a woman KAMALINEE, exuding grace and sophistication", |
| "A woman KAMALINEE dressed as a pirate, in full growth, clear facial features, wearing a 3-cornered hat and black eye patch with hyper realistic background water, photograph taken with 35mm lens, f/1.8, sunlight, natural lighting", |
| ] |
|
|
|
|
| HF_TOKEN = os.getenv("SECRET_TOKEN") |
| callback = gr.HuggingFaceDatasetSaver(HF_TOKEN, "rmx-data") |
|
|
| |
| |
|
|
| with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app: |
| gr.HTML("<center><h1>RMX.1-Dev</h1></center>") |
| with gr.Column(elem_id="app-container"): |
| with gr.Row(): |
| with gr.Column(elem_id="prompt-container"): |
| with gr.Row(): |
| text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input") |
| 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("Run", variant='primary', elem_id="gen-button") |
| with gr.Row(): |
| image_output = gr.Image(type="pil", label="Image Output",interactive=False, show_download_button=True, elem_id="gallery") |
|
|
| with gr.Row(): |
| seed_output = gr.Textbox(label="Seed Used", interactive=False, show_copy_button = True, elem_id="seed-output") |
|
|
| |
| gr.Examples( |
| examples = examples, |
| fn = query, |
| inputs = [text_prompt], |
| ) |
|
|
| |
| |
|
|
|
|
| |
| |
| |
|
|
| |
|
|
| callback.setup([text_prompt, aspect_ratio, steps, cfg, seed_output, strength, image_output], |
| "flagged_data_points") |
|
|
| def truncate_prompts(*args): |
| truncated_text_prompt = args[0][:200] if isinstance(args[0], str) else args[0] |
| return (truncated_text_prompt, *args[1:]) |
|
|
| |
| text_button.click( |
| query, |
| inputs=[text_prompt, aspect_ratio, steps, cfg, seed, strength], |
| outputs=[image_output,seed_output] |
| ).then( |
| lambda *args: callback.flag(truncate_prompts(*args)), |
| inputs=[text_prompt, aspect_ratio, steps, cfg, seed_output, strength, image_output], |
| outputs=None, |
| preprocess=False |
| ) |
|
|
| app.launch(show_api=False, share=False) |