Update app.py
Browse files
app.py
CHANGED
|
@@ -1,73 +1,64 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 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 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 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
|
| 34 |
""")
|
| 35 |
|
| 36 |
with gr.Row():
|
| 37 |
with gr.Column():
|
| 38 |
prompt = gr.Textbox(
|
| 39 |
-
label="
|
| 40 |
-
placeholder="
|
| 41 |
lines=3
|
| 42 |
)
|
| 43 |
negative_prompt = gr.Textbox(
|
| 44 |
-
label="
|
| 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="
|
| 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
|
| 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
|
| 80 |
outputs=output_image
|
| 81 |
)
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
|
|
| 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()
|