app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import random
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Hızlı indirme için Hugging Face ayarı
|
| 7 |
+
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
|
| 8 |
+
|
| 9 |
+
# Model ayarları
|
| 10 |
+
model_id = "stabilityai/sd-turbo"
|
| 11 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
+
pipe = None # Lazy load
|
| 13 |
+
|
| 14 |
+
styles = [
|
| 15 |
+
"punk fashion portrait, neon jacket, futuristic hairstyle, urban background",
|
| 16 |
+
"futuristic metallic outfit, cyberpunk city, glowing textures, sci-fi theme",
|
| 17 |
+
"vintage 80s fashion, colorful retro lighting, analog grain effect",
|
| 18 |
+
"haute couture studio photoshoot, elegant lighting, fashion magazine",
|
| 19 |
+
"streetwear outfit, graffiti wall, baggy hoodie, bold pose",
|
| 20 |
+
"anime inspired outfit, colorful clothing, expressive character art",
|
| 21 |
+
"fantasy armor, cinematic lighting, ethereal atmosphere",
|
| 22 |
+
"minimalist pastel outfit, soft background, calm mood"
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
# Modeli yalnızca ilk çağrıda yükle
|
| 26 |
+
def load_model():
|
| 27 |
+
global pipe
|
| 28 |
+
if pipe is None:
|
| 29 |
+
from diffusers import StableDiffusionPipeline
|
| 30 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 31 |
+
model_id,
|
| 32 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
| 33 |
+
).to(device)
|
| 34 |
+
return pipe
|
| 35 |
+
|
| 36 |
+
def restyle(image, custom_prompt=None):
|
| 37 |
+
pipe = load_model()
|
| 38 |
+
chosen_style = custom_prompt.strip() if custom_prompt else random.choice(styles)
|
| 39 |
+
prompt = f"A portrait of the same person wearing {chosen_style}, ultra realistic, detailed face, professional studio lighting"
|
| 40 |
+
result = pipe(prompt=prompt, image=image, guidance_scale=1.5).images[0]
|
| 41 |
+
return result, f"Kullanılan Stil: {chosen_style}"
|
| 42 |
+
|
| 43 |
+
# --- Gradio Arayüzü ---
|
| 44 |
+
with gr.Blocks(theme=gr.themes.Monochrome(), css="""
|
| 45 |
+
#title {text-align:center; font-size:2em; font-weight:bold; margin-bottom:10px;}
|
| 46 |
+
#desc {text-align:center; font-size:1.1em; color:#cccccc; margin-bottom:25px;}
|
| 47 |
+
footer {visibility:hidden}
|
| 48 |
+
""") as demo:
|
| 49 |
+
|
| 50 |
+
gr.HTML("<div id='title'>🧥 AI Stylist - Turbo Sürüm ⚡</div>")
|
| 51 |
+
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>")
|
| 52 |
+
|
| 53 |
+
with gr.Row():
|
| 54 |
+
with gr.Column(scale=1):
|
| 55 |
+
img_input = gr.Image(type="pil", label="📸 Fotoğrafını Yükle")
|
| 56 |
+
txt_style = gr.Textbox(label="🪄 Özel Stil (boş bırak = rastgele)")
|
| 57 |
+
btn_generate = gr.Button("🎲 Stil Üret / Yeniden Oluştur")
|
| 58 |
+
with gr.Column(scale=1):
|
| 59 |
+
img_output = gr.Image(label="🧢 Yeni Stil")
|
| 60 |
+
txt_output = gr.Textbox(label="Stil Bilgisi", interactive=False)
|
| 61 |
+
|
| 62 |
+
btn_generate.click(fn=restyle, inputs=[img_input, txt_style], outputs=[img_output, txt_output])
|
| 63 |
+
|
| 64 |
+
gr.HTML("<div style='text-align:center; color:#888; margin-top:20px;'>✨ Katake tarafından geliştirildi · AI Stylist Turbo Sürüm</div>")
|
| 65 |
+
|
| 66 |
+
demo.launch()
|