File size: 2,496 Bytes
8923aba
 
9f261f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8923aba
9f261f3
 
 
 
8923aba
9f261f3
 
 
 
 
 
 
 
 
 
8923aba
9f261f3
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
import torch
from diffusers import AutoPipelineForText2Image

def generate_image(prompt, use_tok=True):
    # Eğer use_tok seçeneği işaretlendiyse, prompt'a TOK ekle
    if use_tok and "TOK" not in prompt:
        prompt = f"TOK {prompt}"
    
    # Pipeline oluştur
    try:
        pipeline = AutoPipelineForText2Image.from_pretrained(
            "black-forest-labs/FLUX.1-dev", 
            torch_dtype=torch.float16
        ).to("cuda" if torch.cuda.is_available() else "cpu")
        
        # LoRA ağırlıklarını yükle
        pipeline.load_lora_weights(
            "codermert/malikafinal", 
            weight_name="lora.safetensors"
        )
        
        # Görüntü oluştur
        image = pipeline(prompt).images[0]
        return image, f"Oluşturulan prompt: {prompt}"
    except Exception as e:
        return None, f"Hata oluştu: {str(e)}"

# Gradio arayüzü
with gr.Blocks(title="Malika - FLUX Text-to-Image") as demo:
    gr.Markdown("# Malika - FLUX.1 Text-to-Image Modeliyle Görüntü Oluşturucu")
    gr.Markdown("Bu uygulama, codermert/malikafinal modelini kullanarak metinden görüntü oluşturur.")
    
    with gr.Row():
        with gr.Column():
            prompt_input = gr.Textbox(
                label="Prompt", 
                placeholder="Görüntü için prompt yazın...",
                lines=3
            )
            tok_checkbox = gr.Checkbox(
                label="Otomatik TOK Ekle", 
                value=True, 
                info="İşaretliyse prompt'a otomatik olarak TOK ekler"
            )
            generate_btn = gr.Button("Görüntü Oluştur", variant="primary")
        
        with gr.Column():
            image_output = gr.Image(label="Oluşturulan Görüntü")
            prompt_used = gr.Textbox(label="Kullanılan Prompt")
    
    generate_btn.click(
        fn=generate_image,
        inputs=[prompt_input, tok_checkbox],
        outputs=[image_output, prompt_used]
    )
    
    gr.Markdown("""
    ## Kullanım Tavsiyeleri
    - Eğer model için özel bir trigger sözcüğü gerekliyse 'TOK' seçeneğini işaretli bırakın
    - Daha gerçekçi sonuçlar için "photorealistic, 8K, detailed" gibi ifadeler ekleyebilirsiniz
    - Örnek: "portrait of a woman with blue eyes, photorealistic, 8K"
    
    ## Model Bilgisi
    Bu uygulama codermert/malikafinal modelini kullanmaktadır.
    Base model: black-forest-labs/FLUX.1-dev
    """)

# Arayüzü başlat
demo.launch()