File size: 2,861 Bytes
ef63a65 |
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 |
import os
import random
import gradio as gr
import torch
# Hızlı indirme için Hugging Face ayarı
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
# Model ayarları
model_id = "stabilityai/sd-turbo"
device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = None # Lazy load
styles = [
"punk fashion portrait, neon jacket, futuristic hairstyle, urban background",
"futuristic metallic outfit, cyberpunk city, glowing textures, sci-fi theme",
"vintage 80s fashion, colorful retro lighting, analog grain effect",
"haute couture studio photoshoot, elegant lighting, fashion magazine",
"streetwear outfit, graffiti wall, baggy hoodie, bold pose",
"anime inspired outfit, colorful clothing, expressive character art",
"fantasy armor, cinematic lighting, ethereal atmosphere",
"minimalist pastel outfit, soft background, calm mood"
]
# Modeli yalnızca ilk çağrıda yükle
def load_model():
global pipe
if pipe is None:
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained(
model_id,
torch_dtype=torch.float16 if device == "cuda" else torch.float32
).to(device)
return pipe
def restyle(image, custom_prompt=None):
pipe = load_model()
chosen_style = custom_prompt.strip() if custom_prompt else random.choice(styles)
prompt = f"A portrait of the same person wearing {chosen_style}, ultra realistic, detailed face, professional studio lighting"
result = pipe(prompt=prompt, image=image, guidance_scale=1.5).images[0]
return result, f"Kullanılan Stil: {chosen_style}"
# --- Gradio Arayüzü ---
with gr.Blocks(theme=gr.themes.Monochrome(), css="""
#title {text-align:center; font-size:2em; font-weight:bold; margin-bottom:10px;}
#desc {text-align:center; font-size:1.1em; color:#cccccc; margin-bottom:25px;}
footer {visibility:hidden}
""") as demo:
gr.HTML("<div id='title'>🧥 AI Stylist - Turbo Sürüm ⚡</div>")
gr.HTML("<div id='desc'>Yapay zeka senin fotoğrafına rastgele bir moda stili uygulasın.<br>GPU varsa 5 saniyede, yoksa biraz sabır 🙂</div>")
with gr.Row():
with gr.Column(scale=1):
img_input = gr.Image(type="pil", label="📸 Fotoğrafını Yükle")
txt_style = gr.Textbox(label="🪄 Özel Stil (boş bırak = rastgele)")
btn_generate = gr.Button("🎲 Stil Üret / Yeniden Oluştur")
with gr.Column(scale=1):
img_output = gr.Image(label="🧢 Yeni Stil")
txt_output = gr.Textbox(label="Stil Bilgisi", interactive=False)
btn_generate.click(fn=restyle, inputs=[img_input, txt_style], outputs=[img_output, txt_output])
gr.HTML("<div style='text-align:center; color:#888; margin-top:20px;'>✨ Katake tarafından geliştirildi · AI Stylist Turbo Sürüm</div>")
demo.launch()
|