File size: 9,235 Bytes
2354bdc
 
 
27ee9d2
2354bdc
 
 
27ee9d2
 
2354bdc
 
 
 
 
 
 
27ee9d2
 
 
 
2354bdc
 
 
27ee9d2
2354bdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27ee9d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2354bdc
 
 
 
27ee9d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2354bdc
 
 
 
27ee9d2
2354bdc
 
27ee9d2
 
 
 
 
 
 
2354bdc
 
 
 
27ee9d2
 
2354bdc
27ee9d2
 
2354bdc
 
27ee9d2
 
2354bdc
 
27ee9d2
 
2354bdc
27ee9d2
2354bdc
27ee9d2
2354bdc
27ee9d2
 
 
 
 
 
 
 
 
 
 
2354bdc
27ee9d2
2354bdc
27ee9d2
2354bdc
 
 
 
 
27ee9d2
 
30179cd
27ee9d2
 
2354bdc
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline, DPMSolverMultistepScheduler
import gradio as gr
import torch
from transformers import pipeline
from PIL import Image

model_id = 'Extraphy/mustafa-kemal-ataturkv2'
prefix = 'Atatürk'

scheduler = DPMSolverMultistepScheduler.from_pretrained(model_id, subfolder="scheduler")

pipe = StableDiffusionPipeline.from_pretrained(
  model_id,
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
  scheduler=scheduler)

#pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained(
  #model_id,
  #torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
 # scheduler=scheduler)

if torch.cuda.is_available():
  pipe = pipe.to("cuda")
  #pipe_i2i = pipe_i2i.to("cuda")

def error_str(error, title="Error"):
    return f"""#### {title}
            {error}"""  if error else ""

def inference(prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt="", auto_prefix=False):

  generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
  prompt = f"{prefix} {prompt}" if auto_prefix else prompt

  try:
      return txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator), None
  except Exception as e:
    return None, error_str(e)

def txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator):

    result = pipe(
      prompt,
      negative_prompt = neg_prompt,
      num_inference_steps = int(steps),
      guidance_scale = guidance,
      width = width,
      height = height,
      generator = generator)
    
    return result.images[0]



css = """
.button, input, optgroup, select, textarea {
    font-family: 'Source Sans Pro';
    font-size: 80%;
    font-weight: inherit;
    line-height: inherit;
    color: orangered;
    margin: 0;
    padding: 0;
    font-weight: 600;
}
        .gr-form {
  display: contents;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 50%;
  line-height: 0.9rem;
}

.gr-label {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.gr-input, .gr-select {
  width: 100%;
  font-size: 0.8rem;
  border: 1px solid #f78900;
  border-radius: 0.15rem;
}

.gr-input[type="number"] {
  width: fit-content;
}

.gr-button {
  font-size: 1.2rem;
  padding: 1.5rem 0.2rem;
  border: none;
  border-radius: 0.25rem;
  background-image: linear-gradient(0deg, rgb(15, 54, 96) 0.00%,rgb(252, 133, 123) 99.00%);
  background: linear-gradient(0deg, rgb(185, 54, 96) 0.00%,rgb(252, 133, 123) 99.00%);
  color: #f3f3f3;
  cursor: copy;
}

.gr-button:hover {
  background-color: Red;
}

    
}
.main-div div {
  display: inline-flex;
  align-items: center;
  gap: .8rem;
  font-size: 1.75rem;
}

.main-div div h1 {
  font-weight: 1000;
  margin-bottom: 7px;
}

.main-div p {
  margin-bottom: 10px;
  font-size: 94%;
}

a {
  text-decoration: underline;
}

.tabs {
  margin-top: 0;
  margin-bottom: 0;
}

#gallery {
  min-height: 20rem;
}
.container {
  width: 70%;
}
	  .hcontainer {
  width: 80%;
  display: flex;
  overflow: auto;
  min-height: 185px;
  align-items: center;
  flex-direction: column;
  justify-content: flex-start;
}
.hcontainer1 {
  top: 20px;
  right: 0px;
  width: 100%;
  height: 90px;
  display: flex;
  position: absolute;
  align-items: flex-start;
  border-radius: var(--dl-radius-radius-radius8);
  justify-content: flex-start;
}
.hcontainer2 {
  top: 20px;
  right: 0px;
  width: 100%;
  height: 100%;
  display: flex;
  position: absolute;
  align-items: flex-start;
  border-radius: var(--dl-radius-radius-radius8);
  justify-content: flex-start;
  background-image: linear-gradient(0deg, rgb(185, 54, 96) 0.00%,rgb(252, 133, 123) 99.00%);
}
.home-image {
  top: 0px;
  right: var(--dl-space-space-halfunit);
  width: 50%;
  bottom: 0px;
  margin: auto;
  position: absolute;
  object-fit: cover;
}
.home-image1 {
  top: 17px;
  left: 23px;
  width: 348px;
  height: 52px;
  margin: auto;
  position: absolute;
  align-self: flex-start;
  object-fit: cover;
}
:root {
  --dl-color-gray-500: #595959;
  --dl-color-gray-700: #999999;
  --dl-color-gray-900: #D9D9D9;
  --dl-size-size-large: 144px;
  --dl-size-size-small: 48px;
  --dl-color-danger-300: #A22020;
  --dl-color-danger-500: #BF2626;
  --dl-color-danger-700: #E14747;
  --dl-color-gray-black: #000000;
  --dl-color-gray-white: #FFFFFF;
  --dl-size-size-medium: 96px;
  --dl-size-size-xlarge: 192px;
  --dl-size-size-xsmall: 16px;
  --dl-space-space-unit: 16px;
  --dl-color-primary-100: #003EB3;
  --dl-color-primary-300: #0074F0;
  --dl-color-primary-500: #14A9FF;
  --dl-color-primary-700: #85DCFF;
  --dl-color-success-300: #199033;
  --dl-color-success-500: #32A94C;
  --dl-color-success-700: #4CC366;
  --dl-size-size-xxlarge: 288px;
  --dl-radius-radius-round: 50%;
  --dl-space-space-halfunit: 8px;
  --dl-space-space-sixunits: 96px;
  --dl-space-space-twounits: 32px;
  --dl-radius-radius-radius2: 2px;
  --dl-radius-radius-radius4: 4px;
  --dl-radius-radius-radius8: 8px;
  --dl-space-space-fiveunits: 80px;
  --dl-space-space-fourunits: 64px;
  --dl-space-space-threeunits: 48px;
  --dl-space-space-oneandhalfunits: 24px;
}


"""
with gr.Blocks(css=css) as demo:
    gr.HTML(
        f"""
<div class="hcontainer">
        <div class="hcontainer1">
          <div class="hcontainer2">
            <img
              alt="image"
              src="https://i.imgur.com/mLhGqm1.png"
              class="home-image"
            />
            <img
              alt="image"
              src="https://i.imgur.com/Eq0OK8z.png"
              class="home-image1"
            />
          </div>
        </div>
      </div>
        """
    )
    with gr.Row():
        
        with gr.Column(scale=60):
          with gr.Group():
              with gr.Row():
                prompt = gr.Textbox(label="Prompt", value="Portrait of Atatürk, fantasy, intricate, elegant, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration, artgerm and greg rutkowski and alphonse mucha", 
                                        examples=[
        ["What a beautiful morning for a walk!"],
        ["It was the best of times, it was the worst of times."],
    ],
                                    show_label=False, max_lines=3,placeholder=f"{prefix} [your prompt]").style(container=True)
                generate = gr.Button(value="ÜRET").style(rounded=(False, True, True, False))

              image_out = gr.Image(height=512)
          error_output = gr.Markdown()

        with gr.Column(scale=40):
          with gr.Tab("Seçenekler"):
            with gr.Group():
              neg_prompt = gr.Textbox(label="Negatif Girdi", placeholder="Çıkarılacak Girdiler", value="lowres, text, error, cropped, low quality, duplicate, mutilated, out of frame, extra fingers, mutated hands, mutation, deformed, blurry, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, missing arms, missing legs, fused fingers")
              #auto_prefix = gr.Checkbox(label="Prefix styling tokens automatically (Atatürk)", value=prefix, visible=prefix)

              with gr.Row():
                guidance = gr.Slider(label="Sanat Ölçeği", value=7.5, maximum=15)
                steps = gr.Slider(label="İşlem Adımı", value=25, minimum=2, maximum=75, step=1)

              with gr.Row():
                width = gr.Slider(label="Genişlik", value=512, minimum=64, maximum=1024, step=8)
                height = gr.Slider(label="Yükseklik", value=512, minimum=64, maximum=1024, step=8)

              seed = gr.Slider(0, 2147483647, label='Köken (0 = Rastgele)', value=0, step=1)

          #with gr.Tab("Image to image"):
              with gr.Group():
                gr.Textbox(
            label="Bilgiler",
            lines=3,
            value="Mustafa Kemal Atatürk'ün bilinen ve genç halini üretebileceğiniz bir yapay zeka modeli. Bilinen hali için Atatürk, genç hali için ise GençAtatürk yazabilirsiniz.",
        )




                  #image2 = gr.Image(label="Image", height=256, tool="editor", type="pil")
                #strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)

    #auto_prefix.change(lambda x: gr.update(placeholder=f"{prefix} [your prompt]" if x else "[Your prompt]"), inputs=auto_prefix, outputs=prompt, queue=False)

    inputs = [prompt, guidance, steps, width, height, seed, neg_prompt]
    outputs = [image_out, error_output]
    prompt.submit(inference, inputs=inputs, outputs=outputs)
    generate.click(inference, inputs=inputs, outputs=outputs)

    gr.HTML("""
    <div style="border-top: 1px solid #303030;" align="right">
<br> <p style="text-align: right;font-size: 160%;">Daha fazla bilgi için <a href="https://twitter.com/skbulous" target="_blank">SKB</a></p><br>
   <p style="text-align: right;" ><a href="https://merzigo.com/"><img src="https://i.imgur.com/Gsifypg.png" align="right"></a>
      <br><br><br>
      <p style="text-align: right;">This space was created using <a href="https://huggingface.co/spaces/anzorq/sd-space-creator">SD Space Creator</a>.</p>
    </div>
    """)

demo.queue(concurrency_count=1)
demo.launch()