Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from diffusers import StableDiffusionPipeline
|
| 3 |
-
import torch
|
| 4 |
-
|
| 5 |
-
# Список доступних моделей
|
| 6 |
-
MODELS = {
|
| 7 |
-
"Stable Diffusion v1.5": "runwayml/stable-diffusion-v1-5",
|
| 8 |
-
"Stable Diffusion 2.1 Base": "stabilityai/stable-diffusion-2-1-base",
|
| 9 |
-
"Stable Diffusion XL": "stabilityai/stable-diffusion-xl-base-1.0"
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
# Кеш для завантажених пайплайнів
|
| 13 |
-
loaded_pipes = {}
|
| 14 |
-
|
| 15 |
-
def get_pipe(model_name):
|
| 16 |
-
if model_name not in loaded_pipes:
|
| 17 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
| 18 |
-
MODELS[model_name],
|
| 19 |
-
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
| 20 |
-
)
|
| 21 |
-
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 22 |
-
loaded_pipes[model_name] = pipe
|
| 23 |
-
return loaded_pipes[model_name]
|
| 24 |
-
|
| 25 |
-
def generate(prompt, model_name):
|
| 26 |
-
pipe = get_pipe(model_name)
|
| 27 |
-
result = pipe(prompt)
|
| 28 |
-
return result.images[0]
|
| 29 |
-
|
| 30 |
-
demo = gr.Interface(
|
| 31 |
-
fn=generate,
|
| 32 |
-
inputs=[
|
| 33 |
-
gr.Textbox(label="Prompt", placeholder="Напиши опис сюди"),
|
| 34 |
-
gr.Dropdown(choices=list(MODELS.keys()), value="Stable Diffusion v1.5", label="Модель")
|
| 35 |
-
],
|
| 36 |
-
outputs=gr.Image(label="Result"),
|
| 37 |
-
title="AI Image Generator (Multiple Models)"
|
| 38 |
-
)
|
| 39 |
-
|
| 40 |
-
demo.launch(ssr_mode=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|