| import gradio as gr |
| from diffusers import StableDiffusionPipeline |
| import torch |
| import time |
|
|
| |
| MODELS = { |
| "Realistic": "visionpy_realistic", |
| "Anime": "visionpy_anime" |
| } |
|
|
| |
| def load_model(mode): |
| pipe = StableDiffusionPipeline.from_pretrained( |
| MODELS[mode], |
| torch_dtype=torch.float16 |
| ).to("cuda") |
| |
| |
| |
| return pipe |
|
|
| |
| def generate(prompt, mode, res): |
| pipe = load_model(mode) |
| start_time = time.time() |
|
|
| |
| 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!" |
|
|
| |
| 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() |