|
import gradio as gr |
|
from huggingface_hub import InferenceClient |
|
import os |
|
|
|
|
|
HF_TOKEN = os.getenv("HF_TOKEN") |
|
|
|
client = InferenceClient( |
|
provider="hf-inference", |
|
token=HF_TOKEN, |
|
) |
|
|
|
def generate_image(prompt, negative_prompt): |
|
|
|
if not prompt.startswith("TOK"): |
|
prompt = "TOK, " + prompt |
|
|
|
try: |
|
|
|
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) |
|
|
|
|
|
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!") |
|
|
|
|
|
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, |
|
) |
|
|
|
|
|
generate_btn.click( |
|
fn=generate_image, |
|
inputs=[prompt, negative_prompt], |
|
outputs=output_image |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |