File size: 1,791 Bytes
61f3dfd | 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 | import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
import time
# MODELLER
MODELS = {
"Realistic": "visionpy_realistic",
"Anime": "visionpy_anime"
}
# MODEL YÜKLEME
def load_model(mode):
pipe = StableDiffusionPipeline.from_pretrained(
MODELS[mode],
torch_dtype=torch.float16
).to("cuda")
# Hız optimizasyonu
# xFormers destekleniyorsa uncomment:
# pipe.enable_xformers_memory_efficient_attention()
return pipe
# ANA ÜRETİM FONKSİYONU
def generate(prompt, mode, res):
pipe = load_model(mode)
start_time = time.time()
# Çözünürlük
if res == "512p":
w, h = 512, 512
steps = 20
elif res == "1024p":
w, h = 1024, 1024
steps = 25
else:
w, h = 512, 512
steps = 20
image = pipe(prompt, height=h, width=w, num_inference_steps=steps, guidance_scale=7.5).images[0]
elapsed = time.time() - start_time
return image, f"{elapsed:.2f} saniyede üretildi!"
# GRADIO ARAYÜZÜ
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown(
"<h1 style='text-align:center'>🌟 Hh — VisionPy Ultra HD (11s Mode)</h1>"
"<p style='text-align:center'>Anime / Realistic Modları, 512-1024p hızlı üretim, Light Theme</p>"
)
with gr.Row():
prompt = gr.Textbox(label="Prompt", placeholder="ör: fantastik şehir ultra yüksek çözünürlük")
mode = gr.Dropdown(["Realistic", "Anime"], label="Mod")
res = gr.Dropdown(["512p", "1024p"], label="Çözünürlük (Hızlı Mod)")
out = gr.Image(label="Sonuç")
time_label = gr.Label(label="Üretim Süresi")
btn = gr.Button("ÜRET")
btn.click(generate, inputs=[prompt, mode, res], outputs=[out, time_label])
demo.launch() |