|
import gradio as gr |
|
from diffusers import AutoPipelineForText2Image |
|
import torch |
|
|
|
|
|
device = "cuda" if torch.cuda.is_available() else "cpu" |
|
pipeline = AutoPipelineForText2Image.from_pretrained( |
|
"black-forest-labs/FLUX.1-dev", |
|
torch_dtype=torch.float16 |
|
).to(device) |
|
|
|
|
|
pipeline.load_lora_weights("codermert/gamzekocc_fluxx", weight_name="lora.safetensors") |
|
|
|
def generate_image(prompt, negative_prompt, guidance_scale): |
|
|
|
if not prompt.startswith("TOK"): |
|
prompt = "TOK, " + prompt |
|
|
|
|
|
image = pipeline( |
|
prompt=prompt, |
|
negative_prompt=negative_prompt, |
|
guidance_scale=float(guidance_scale) |
|
).images[0] |
|
|
|
return image |
|
|
|
|
|
with gr.Blocks(title="Mert Baba'nın Görsel Oluşturucusu") as demo: |
|
gr.Markdown(""" |
|
# 🎨 Mert Baba'nın AI Görsel Oluşturucusu |
|
FLUX LoRA modeli ile özel görseller oluşturun! |
|
""") |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
prompt = gr.Textbox( |
|
label="Prompt", |
|
placeholder="Görsel için açıklama girin...", |
|
lines=3 |
|
) |
|
negative_prompt = gr.Textbox( |
|
label="Negative Prompt", |
|
value="blurry, bad quality, worst quality, jpeg artifacts", |
|
lines=2 |
|
) |
|
guidance_scale = gr.Slider( |
|
minimum=1, |
|
maximum=20, |
|
value=7.5, |
|
step=0.5, |
|
label="Guidance Scale" |
|
) |
|
generate_btn = gr.Button("Görsel Oluştur 🎨") |
|
|
|
with gr.Column(): |
|
output_image = gr.Image(label="Oluşturulan Görsel") |
|
|
|
|
|
gr.Examples( |
|
examples=[ |
|
["A striking woman lit with bi-color directional lighting poses", |
|
"blurry, bad quality, worst quality, jpeg artifacts", |
|
7.5], |
|
["A beautiful portrait photo in a city", |
|
"blurry, bad quality", |
|
7.5], |
|
], |
|
inputs=[prompt, negative_prompt, guidance_scale], |
|
outputs=output_image, |
|
fn=generate_image, |
|
cache_examples=True, |
|
) |
|
|
|
|
|
generate_btn.click( |
|
fn=generate_image, |
|
inputs=[prompt, negative_prompt, guidance_scale], |
|
outputs=output_image |
|
) |
|
|
|
demo.launch() |