Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import time
|
3 |
+
import random
|
4 |
+
|
5 |
+
# Список моделей с отображаемыми названиями и внутренними именами
|
6 |
+
models = {
|
7 |
+
"FLUX.1-dev": "black-forest-labs/FLUX.1-dev",
|
8 |
+
"flux-RealismLora": "XLabs-AI/flux-RealismLora",
|
9 |
+
"Midjourney": "Jovie/Midjourney",
|
10 |
+
"Stable Diffusion v1-5": "stable-diffusion-v1-5/stable-diffusion-v1-5",
|
11 |
+
"Pixel Art XL": "nerijs/pixel-art-xl",
|
12 |
+
"Knitted Character Flux LoRA": "prithivMLmods/Knitted-Character-Flux-LoRA",
|
13 |
+
"Flux Ghibsky Illustration": "aleksa-codes/flux-ghibsky-illustration",
|
14 |
+
"Flux Super Realism LoRA": "strangerzonehf/Flux-Super-Realism-LoRA",
|
15 |
+
"Flux Game Assets LoRA v2": "gokaygokay/Flux-Game-Assets-LoRA-v2",
|
16 |
+
"Flux Animex v2 LoRA": "strangerzonehf/Flux-Animex-v2-LoRA",
|
17 |
+
"Flux Qwen Capybara": "cfahlgren1/flux-qwen-capybara",
|
18 |
+
"Softserve Anime": "alvdansen/softserve_anime",
|
19 |
+
"FLUX Aesthetic Anime": "dataautogpt3/FLUX-AestheticAnime",
|
20 |
+
"FLUX Animeo v1 LoRA": "strangerzonehf/Flux-Animeo-v1-LoRA",
|
21 |
+
"Fractured Line Flare": "prithivMLmods/Fractured-Line-Flare",
|
22 |
+
"Castor 3D Portrait Flux LoRA": "prithivMLmods/Castor-3D-Portrait-Flux-LoRA"
|
23 |
+
}
|
24 |
+
|
25 |
+
# Очередь на генерации
|
26 |
+
queue = []
|
27 |
+
|
28 |
+
def generate_image(model_name, width, height, seed, steps, guidance_scale):
|
29 |
+
# Проверка очереди
|
30 |
+
if len(queue) >= 150:
|
31 |
+
return "Очередь переполнена. Пожалуйста, подождите."
|
32 |
+
|
33 |
+
# Добавляем задачу в очередь
|
34 |
+
task_id = random.randint(100000, 999999)
|
35 |
+
queue.append(task_id)
|
36 |
+
|
37 |
+
# Имитация генерации изображения
|
38 |
+
time.sleep(random.uniform(0.1, 1.0)) # Таймаут до 1 секунды
|
39 |
+
|
40 |
+
# Удаляем задачу из очереди
|
41 |
+
queue.remove(task_id)
|
42 |
+
|
43 |
+
# Имитация изображения
|
44 |
+
image = f"generated_images/{task_id}.png"
|
45 |
+
return image
|
46 |
+
|
47 |
+
# Создание интерфейса
|
48 |
+
with gr.Blocks() as demo:
|
49 |
+
gr.Markdown("# Генератор изображений")
|
50 |
+
|
51 |
+
with gr.Row():
|
52 |
+
model_dropdown = gr.Dropdown(list(models.keys()), label="Модель")
|
53 |
+
|
54 |
+
with gr.Row():
|
55 |
+
with gr.Column():
|
56 |
+
width_slider = gr.Slider(128, 1024, value=512, step=64, label="Ширина")
|
57 |
+
with gr.Column():
|
58 |
+
height_slider = gr.Slider(128, 1024, value=512, step=64, label="Высота")
|
59 |
+
|
60 |
+
with gr.Row():
|
61 |
+
seed_slider = gr.Slider(0, 1000000, value=random.randint(0, 1000000), step=1, label="Сид")
|
62 |
+
|
63 |
+
with gr.Row():
|
64 |
+
steps_slider = gr.Slider(1, 100, value=50, step=1, label="Шаги")
|
65 |
+
guidance_scale_slider = gr.Slider(0.1, 20.0, value=7.5, step=0.1, label="Гуидансе скала")
|
66 |
+
|
67 |
+
generate_button = gr.Button("Сгенерировать изображение")
|
68 |
+
output_image = gr.Image(label="Сгенерированное изображение")
|
69 |
+
|
70 |
+
generate_button.click(
|
71 |
+
fn=generate_image,
|
72 |
+
inputs=[model_dropdown, width_slider, height_slider, seed_slider, steps_slider, guidance_scale_slider],
|
73 |
+
outputs=output_image,
|
74 |
+
api_name="/generate"
|
75 |
+
)
|
76 |
+
|
77 |
+
demo.queue(max_size=150, api_open=False)
|
78 |
+
demo.launch(share=False, server_port=7860)
|
79 |
+
|
80 |
+
# Скрытие футера
|
81 |
+
hide_footer = """
|
82 |
+
<style>
|
83 |
+
.gradio-container .footer {
|
84 |
+
display: none !important;
|
85 |
+
}
|
86 |
+
</style>
|
87 |
+
"""
|
88 |
+
demo = demo.add_css(hide_footer)
|
89 |
+
|
90 |
+
# Установка таймаута
|
91 |
+
demo.queue(api_name="/generate").set_config(max_size=150, api_open=False, max_threads=1, timeout=125)
|
92 |
+
|
93 |
+
demo.launch()
|