codermert commited on
Commit
424f1b5
·
verified ·
1 Parent(s): da7c414

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -39
app.py CHANGED
@@ -1,73 +1,64 @@
1
  import gradio as gr
2
- from diffusers import AutoPipelineForText2Image
3
- import torch
4
 
5
- # Model ve pipeline kurulumu
6
- device = "cuda" if torch.cuda.is_available() else "cpu"
7
- pipeline = AutoPipelineForText2Image.from_pretrained(
8
- "black-forest-labs/FLUX.1-dev",
9
- torch_dtype=torch.float16
10
- ).to(device)
 
11
 
12
- # LoRA modelini yükle
13
- pipeline.load_lora_weights("codermert/gamzekocc_fluxx", weight_name="lora.safetensors")
14
-
15
- def generate_image(prompt, negative_prompt, guidance_scale):
16
  # TOK trigger'ını otomatik ekle
17
  if not prompt.startswith("TOK"):
18
  prompt = "TOK, " + prompt
19
 
20
- # Görseli oluştur
21
- image = pipeline(
22
- prompt=prompt,
23
- negative_prompt=negative_prompt,
24
- guidance_scale=float(guidance_scale)
25
- ).images[0]
26
-
27
- return image
 
 
28
 
29
  # Gradio arayüzü
30
  with gr.Blocks(title="Mert Baba'nın Görsel Oluşturucusu") as demo:
31
  gr.Markdown("""
32
  # 🎨 Mert Baba'nın AI Görsel Oluşturucusu
33
- FLUX LoRA modeli ile özel görseller oluşturun!
34
  """)
35
 
36
  with gr.Row():
37
  with gr.Column():
38
  prompt = gr.Textbox(
39
- label="Prompt",
40
- placeholder="Görsel için açıklama girin...",
41
  lines=3
42
  )
43
  negative_prompt = gr.Textbox(
44
- label="Negative Prompt",
45
  value="blurry, bad quality, worst quality, jpeg artifacts",
46
  lines=2
47
  )
48
- guidance_scale = gr.Slider(
49
- minimum=1,
50
- maximum=20,
51
- value=7.5,
52
- step=0.5,
53
- label="Guidance Scale"
54
- )
55
  generate_btn = gr.Button("Görsel Oluştur 🎨")
56
 
57
  with gr.Column():
58
- output_image = gr.Image(label="Oluşturulan Görsel")
59
 
60
  # Örnek promptlar
61
  gr.Examples(
62
  examples=[
63
  ["A striking woman lit with bi-color directional lighting poses",
64
- "blurry, bad quality, worst quality, jpeg artifacts",
65
- 7.5],
66
  ["A beautiful portrait photo in a city",
67
- "blurry, bad quality",
68
- 7.5],
69
  ],
70
- inputs=[prompt, negative_prompt, guidance_scale],
71
  outputs=output_image,
72
  fn=generate_image,
73
  cache_examples=True,
@@ -76,8 +67,10 @@ with gr.Blocks(title="Mert Baba'nın Görsel Oluşturucusu") as demo:
76
  # Butona tıklayınca çalışacak fonksiyon
77
  generate_btn.click(
78
  fn=generate_image,
79
- inputs=[prompt, negative_prompt, guidance_scale],
80
  outputs=output_image
81
  )
82
 
83
- demo.launch()
 
 
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
 
5
+ # API anahtarını güvenli bir şekilde kullan
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
+ # Inference Client'ı oluştur
8
+ client = InferenceClient(
9
+ provider="hf-inference",
10
+ token=HF_TOKEN,
11
+ )
12
 
13
+ def generate_image(prompt, negative_prompt):
 
 
 
14
  # TOK trigger'ını otomatik ekle
15
  if not prompt.startswith("TOK"):
16
  prompt = "TOK, " + prompt
17
 
18
+ try:
19
+ # Görseli oluştur
20
+ image = client.text_to_image(
21
+ prompt,
22
+ model="black-forest-labs/FLUX.1-dev",
23
+ negative_prompt=negative_prompt
24
+ )
25
+ return image
26
+ except Exception as e:
27
+ return str(e)
28
 
29
  # Gradio arayüzü
30
  with gr.Blocks(title="Mert Baba'nın Görsel Oluşturucusu") as demo:
31
  gr.Markdown("""
32
  # 🎨 Mert Baba'nın AI Görsel Oluşturucusu
33
+ FLUX modeli ile harika görseller oluşturun!
34
  """)
35
 
36
  with gr.Row():
37
  with gr.Column():
38
  prompt = gr.Textbox(
39
+ label="Ne tür bir görsel istersin?",
40
+ placeholder="Örnek: A beautiful portrait photo in a city",
41
  lines=3
42
  )
43
  negative_prompt = gr.Textbox(
44
+ label="İstemediğin özellikler",
45
  value="blurry, bad quality, worst quality, jpeg artifacts",
46
  lines=2
47
  )
 
 
 
 
 
 
 
48
  generate_btn = gr.Button("Görsel Oluştur 🎨")
49
 
50
  with gr.Column():
51
+ output_image = gr.Image(label="İşte görselin!")
52
 
53
  # Örnek promptlar
54
  gr.Examples(
55
  examples=[
56
  ["A striking woman lit with bi-color directional lighting poses",
57
+ "blurry, bad quality, worst quality, jpeg artifacts"],
 
58
  ["A beautiful portrait photo in a city",
59
+ "blurry, bad quality"],
 
60
  ],
61
+ inputs=[prompt, negative_prompt],
62
  outputs=output_image,
63
  fn=generate_image,
64
  cache_examples=True,
 
67
  # Butona tıklayınca çalışacak fonksiyon
68
  generate_btn.click(
69
  fn=generate_image,
70
+ inputs=[prompt, negative_prompt],
71
  outputs=output_image
72
  )
73
 
74
+ # Uygulamayı başlat
75
+ if __name__ == "__main__":
76
+ demo.launch()