Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,72 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
import
|
|
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
base_model.load_lora_weights(lora_model_id)
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
)
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import replicate
|
3 |
+
import random
|
4 |
+
import os
|
5 |
|
6 |
+
def query(prompt, aspect_ratio="1:1", steps=28, cfg_scale=3.5, seed=-1, strength=0.95):
|
7 |
+
if seed == -1:
|
8 |
+
seed = random.randint(1, 1000000000)
|
9 |
+
|
10 |
+
input = {
|
11 |
+
"prompt": prompt,
|
12 |
+
"hf_lora": "codermert/mert_flux",
|
13 |
+
"output_format": "jpg",
|
14 |
+
"aspect_ratio": aspect_ratio,
|
15 |
+
"num_inference_steps": steps,
|
16 |
+
"guidance_scale": cfg_scale,
|
17 |
+
"lora_scale": strength,
|
18 |
+
"seed": seed,
|
19 |
+
"disable_safety_checker": True
|
20 |
+
}
|
21 |
+
|
22 |
+
output = replicate.run(
|
23 |
+
"lucataco/flux-dev-lora:a22c463f11808638ad5e2ebd582e07a469031f48dd567366fb4c6fdab91d614d",
|
24 |
+
input=input
|
25 |
+
)
|
26 |
|
27 |
+
print(output)
|
28 |
+
return output[0], seed
|
|
|
29 |
|
30 |
+
css = """
|
31 |
+
#app-container {
|
32 |
+
max-width: 600px;
|
33 |
+
margin-left: auto;
|
34 |
+
margin-right: auto;
|
35 |
+
}
|
36 |
+
"""
|
37 |
+
|
38 |
+
examples = [
|
39 |
+
"A beautiful landscape with mountains and a lake",
|
40 |
+
"A futuristic cityscape at night",
|
41 |
+
"A portrait of a smiling person in a colorful outfit",
|
42 |
+
]
|
43 |
+
|
44 |
+
with gr.Blocks(theme='default', css=css) as app:
|
45 |
+
gr.HTML("<center><h1>Mert Flux Image Generator</h1></center>")
|
46 |
+
with gr.Column(elem_id="app-container"):
|
47 |
+
with gr.Row():
|
48 |
+
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2)
|
49 |
+
with gr.Row():
|
50 |
+
with gr.Accordion("Advanced Settings", open=False):
|
51 |
+
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"])
|
52 |
+
steps = gr.Slider(label="Sampling steps", value=28, minimum=1, maximum=100, step=1)
|
53 |
+
cfg = gr.Slider(label="CFG Scale", value=3.5, minimum=1, maximum=20, step=0.5)
|
54 |
+
strength = gr.Slider(label="Strength", value=0.95, minimum=0, maximum=1, step=0.001)
|
55 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
56 |
+
|
57 |
+
with gr.Row():
|
58 |
+
text_button = gr.Button("Generate", variant='primary')
|
59 |
+
with gr.Row():
|
60 |
+
image_output = gr.Image(type="pil", label="Generated Image", show_download_button=True)
|
61 |
+
with gr.Row():
|
62 |
+
seed_output = gr.Textbox(label="Seed Used", show_copy_button=True)
|
63 |
+
|
64 |
+
gr.Examples(examples=examples, inputs=[text_prompt])
|
65 |
+
|
66 |
+
text_button.click(
|
67 |
+
query,
|
68 |
+
inputs=[text_prompt, aspect_ratio, steps, cfg, seed, strength],
|
69 |
+
outputs=[image_output, seed_output]
|
70 |
+
)
|
71 |
+
|
72 |
+
app.launch(show_api=False)
|