Update app.py
Browse files
app.py
CHANGED
@@ -1,154 +1,70 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
import random
|
4 |
-
|
5 |
-
# import spaces #[uncomment to use ZeroGPU]
|
6 |
-
from diffusers import DiffusionPipeline
|
7 |
import torch
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
if
|
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 |
-
num_inference_steps=num_inference_steps,
|
46 |
-
width=width,
|
47 |
-
height=height,
|
48 |
-
generator=generator,
|
49 |
-
).images[0]
|
50 |
-
|
51 |
-
return image, seed
|
52 |
-
|
53 |
-
|
54 |
-
examples = [
|
55 |
-
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
56 |
-
"An astronaut riding a green horse",
|
57 |
-
"A delicious ceviche cheesecake slice",
|
58 |
-
]
|
59 |
-
|
60 |
-
css = """
|
61 |
-
#col-container {
|
62 |
-
margin: 0 auto;
|
63 |
-
max-width: 640px;
|
64 |
-
}
|
65 |
-
"""
|
66 |
-
|
67 |
-
with gr.Blocks(css=css) as demo:
|
68 |
-
with gr.Column(elem_id="col-container"):
|
69 |
-
gr.Markdown(" # Text-to-Image Gradio Template")
|
70 |
-
|
71 |
-
with gr.Row():
|
72 |
-
prompt = gr.Text(
|
73 |
-
label="Prompt",
|
74 |
-
show_label=False,
|
75 |
-
max_lines=1,
|
76 |
-
placeholder="Enter your prompt",
|
77 |
-
container=False,
|
78 |
)
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
with gr.Accordion("Advanced Settings", open=False):
|
85 |
-
negative_prompt = gr.Text(
|
86 |
-
label="Negative prompt",
|
87 |
-
max_lines=1,
|
88 |
-
placeholder="Enter a negative prompt",
|
89 |
-
visible=False,
|
90 |
)
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
with gr.Row():
|
103 |
-
width = gr.Slider(
|
104 |
-
label="Width",
|
105 |
-
minimum=256,
|
106 |
-
maximum=MAX_IMAGE_SIZE,
|
107 |
-
step=32,
|
108 |
-
value=1024, # Replace with defaults that work for your model
|
109 |
-
)
|
110 |
-
|
111 |
-
height = gr.Slider(
|
112 |
-
label="Height",
|
113 |
-
minimum=256,
|
114 |
-
maximum=MAX_IMAGE_SIZE,
|
115 |
-
step=32,
|
116 |
-
value=1024, # Replace with defaults that work for your model
|
117 |
-
)
|
118 |
-
|
119 |
-
with gr.Row():
|
120 |
-
guidance_scale = gr.Slider(
|
121 |
-
label="Guidance scale",
|
122 |
-
minimum=0.0,
|
123 |
-
maximum=10.0,
|
124 |
-
step=0.1,
|
125 |
-
value=0.0, # Replace with defaults that work for your model
|
126 |
-
)
|
127 |
-
|
128 |
-
num_inference_steps = gr.Slider(
|
129 |
-
label="Number of inference steps",
|
130 |
-
minimum=1,
|
131 |
-
maximum=50,
|
132 |
-
step=1,
|
133 |
-
value=2, # Replace with defaults that work for your model
|
134 |
-
)
|
135 |
-
|
136 |
-
gr.Examples(examples=examples, inputs=[prompt])
|
137 |
-
gr.on(
|
138 |
-
triggers=[run_button.click, prompt.submit],
|
139 |
-
fn=infer,
|
140 |
-
inputs=[
|
141 |
-
prompt,
|
142 |
-
negative_prompt,
|
143 |
-
seed,
|
144 |
-
randomize_seed,
|
145 |
-
width,
|
146 |
-
height,
|
147 |
-
guidance_scale,
|
148 |
-
num_inference_steps,
|
149 |
-
],
|
150 |
-
outputs=[result, seed],
|
151 |
)
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
import torch
|
3 |
+
from diffusers import AutoPipelineForText2Image
|
4 |
+
|
5 |
+
def generate_image(prompt, use_tok=True):
|
6 |
+
# Eğer use_tok seçeneği işaretlendiyse, prompt'a TOK ekle
|
7 |
+
if use_tok and "TOK" not in prompt:
|
8 |
+
prompt = f"TOK {prompt}"
|
9 |
+
|
10 |
+
# Pipeline oluştur
|
11 |
+
try:
|
12 |
+
pipeline = AutoPipelineForText2Image.from_pretrained(
|
13 |
+
"black-forest-labs/FLUX.1-dev",
|
14 |
+
torch_dtype=torch.float16
|
15 |
+
).to("cuda" if torch.cuda.is_available() else "cpu")
|
16 |
+
|
17 |
+
# LoRA ağırlıklarını yükle
|
18 |
+
pipeline.load_lora_weights(
|
19 |
+
"codermert/malikafinal",
|
20 |
+
weight_name="lora.safetensors"
|
21 |
+
)
|
22 |
+
|
23 |
+
# Görüntü oluştur
|
24 |
+
image = pipeline(prompt).images[0]
|
25 |
+
return image, f"Oluşturulan prompt: {prompt}"
|
26 |
+
except Exception as e:
|
27 |
+
return None, f"Hata oluştu: {str(e)}"
|
28 |
+
|
29 |
+
# Gradio arayüzü
|
30 |
+
with gr.Blocks(title="Malika - FLUX Text-to-Image") as demo:
|
31 |
+
gr.Markdown("# Malika - FLUX.1 Text-to-Image Modeliyle Görüntü Oluşturucu")
|
32 |
+
gr.Markdown("Bu uygulama, codermert/malikafinal modelini kullanarak metinden görüntü oluşturur.")
|
33 |
+
|
34 |
+
with gr.Row():
|
35 |
+
with gr.Column():
|
36 |
+
prompt_input = gr.Textbox(
|
37 |
+
label="Prompt",
|
38 |
+
placeholder="Görüntü için prompt yazın...",
|
39 |
+
lines=3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
)
|
41 |
+
tok_checkbox = gr.Checkbox(
|
42 |
+
label="Otomatik TOK Ekle",
|
43 |
+
value=True,
|
44 |
+
info="İşaretliyse prompt'a otomatik olarak TOK ekler"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
)
|
46 |
+
generate_btn = gr.Button("Görüntü Oluştur", variant="primary")
|
47 |
+
|
48 |
+
with gr.Column():
|
49 |
+
image_output = gr.Image(label="Oluşturulan Görüntü")
|
50 |
+
prompt_used = gr.Textbox(label="Kullanılan Prompt")
|
51 |
+
|
52 |
+
generate_btn.click(
|
53 |
+
fn=generate_image,
|
54 |
+
inputs=[prompt_input, tok_checkbox],
|
55 |
+
outputs=[image_output, prompt_used]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
)
|
57 |
+
|
58 |
+
gr.Markdown("""
|
59 |
+
## Kullanım Tavsiyeleri
|
60 |
+
- Eğer model için özel bir trigger sözcüğü gerekliyse 'TOK' seçeneğini işaretli bırakın
|
61 |
+
- Daha gerçekçi sonuçlar için "photorealistic, 8K, detailed" gibi ifadeler ekleyebilirsiniz
|
62 |
+
- Örnek: "portrait of a woman with blue eyes, photorealistic, 8K"
|
63 |
+
|
64 |
+
## Model Bilgisi
|
65 |
+
Bu uygulama codermert/malikafinal modelini kullanmaktadır.
|
66 |
+
Base model: black-forest-labs/FLUX.1-dev
|
67 |
+
""")
|
68 |
+
|
69 |
+
# Arayüzü başlat
|
70 |
+
demo.launch()
|