File size: 2,228 Bytes
39ac521 424f1b5 39ac521 424f1b5 a951bd6 424f1b5 a951bd6 424f1b5 a951bd6 424f1b5 a951bd6 424f1b5 a951bd6 39ac521 a951bd6 424f1b5 a951bd6 39ac521 a951bd6 424f1b5 a951bd6 424f1b5 a951bd6 424f1b5 39ac521 424f1b5 a951bd6 424f1b5 a951bd6 39ac521 424f1b5 |
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 |
import gradio as gr
from huggingface_hub import InferenceClient
import os
# API anahtarını güvenli bir şekilde kullan
HF_TOKEN = os.getenv("HF_TOKEN")
# Inference Client'ı oluştur
client = InferenceClient(
provider="hf-inference",
token=HF_TOKEN,
)
def generate_image(prompt, negative_prompt):
# TOK trigger'ını otomatik ekle
if not prompt.startswith("TOK"):
prompt = "TOK, " + prompt
try:
# Görseli oluştur
image = client.text_to_image(
prompt,
model="black-forest-labs/FLUX.1-dev",
negative_prompt=negative_prompt
)
return image
except Exception as e:
return str(e)
# Gradio arayüzü
with gr.Blocks(title="Mert Baba'nın Görsel Oluşturucusu") as demo:
gr.Markdown("""
# 🎨 Mert Baba'nın AI Görsel Oluşturucusu
FLUX modeli ile harika görseller oluşturun!
""")
with gr.Row():
with gr.Column():
prompt = gr.Textbox(
label="Ne tür bir görsel istersin?",
placeholder="Örnek: A beautiful portrait photo in a city",
lines=3
)
negative_prompt = gr.Textbox(
label="İstemediğin özellikler",
value="blurry, bad quality, worst quality, jpeg artifacts",
lines=2
)
generate_btn = gr.Button("Görsel Oluştur 🎨")
with gr.Column():
output_image = gr.Image(label="İşte görselin!")
# Örnek promptlar
gr.Examples(
examples=[
["A striking woman lit with bi-color directional lighting poses",
"blurry, bad quality, worst quality, jpeg artifacts"],
["A beautiful portrait photo in a city",
"blurry, bad quality"],
],
inputs=[prompt, negative_prompt],
outputs=output_image,
fn=generate_image,
cache_examples=True,
)
# Butona tıklayınca çalışacak fonksiyon
generate_btn.click(
fn=generate_image,
inputs=[prompt, negative_prompt],
outputs=output_image
)
# Uygulamayı başlat
if __name__ == "__main__":
demo.launch() |