Download app.py from Katake/style: direct link, hf CLI and curl.
- Browser
- Download file 2.86 kB
-
https://huggingface.co/spaces/Katake/style/resolve/main/app.py
- Command line
-
hf download hf://spaces/Katake/style/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Katake/style/resolve/main/app.py
2.86 kB
| 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() | |