Hh / python.py
1c1's picture
Create python.py
61f3dfd verified
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()