Rooni commited on
Commit
687d54f
·
verified ·
1 Parent(s): eb75e63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -5
app.py CHANGED
@@ -2,11 +2,65 @@ import gradio as gr
2
  import requests
3
  import random
4
 
5
- def generate_image(prompt, width, height, seed):
6
  if seed == -1:
7
  seed = random.randint(0, 999999)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  url = f"https://image.pollinations.ai/prompt/{prompt}?width={width}&height={height}&seed={seed}&nologo=true&nofeed=true"
9
- response = requests.get(url)
10
  if response.status_code == 200:
11
  return response.content
12
  else:
@@ -15,16 +69,66 @@ def generate_image(prompt, width, height, seed):
15
  # Создаем интерфейс Gradio
16
  with gr.Blocks() as demo:
17
  with gr.Tab("Основные настройки"):
18
- prompt_input = gr.Textbox(label="Промпт", placeholder="Введите промпт на английском языке")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  with gr.Tab("Дополнительные настройки"):
21
  width_slider = gr.Slider(label="Ширина", minimum=1, maximum=4000, value=1024)
22
- height_slider = gr.Slider(label="Высота", minimum=1, maximum=4000, value=512)
23
  seed_slider = gr.Slider(label="Сид", minimum=-1, maximum=999999, value=-1, step=1)
24
 
25
  create_button = gr.Button("Создать")
26
  output_image = gr.Image(label="Изображение", type="pil") # Указываем тип вывода как PIL изображение
27
 
28
- create_button.click(fn=generate_image, inputs=[prompt_input, width_slider, height_slider, seed_slider], outputs=output_image)
29
 
30
  demo.launch()
 
2
  import requests
3
  import random
4
 
5
+ def generate_image(prompt, style, width, height, seed):
6
  if seed == -1:
7
  seed = random.randint(0, 999999)
8
+
9
+ # Добавляем теги для стилей
10
+ style_tags = {
11
+ "Свой": "",
12
+ "Аниме": "anime style, detailed, vibrant colors, cartoonish",
13
+ "Реализм": "realism style, hyperrealistic, photorealistic",
14
+ "3D": "3D style, rendering, high detail, volumetric lighting",
15
+ "Краски": "paintings style, impressionist, detailed brush strokes, oil painting",
16
+ "Пиксель-арт": "pixel art style, low resolution, retro, nostalgic",
17
+ "Машины с лицами": "machines with faces, mechanical humanoid, futuristic, detailed features",
18
+ "Космический": "space style, celestial bodies, galaxies, stars, nebulae",
19
+ "Монстры": "monster style, mythical creatures, detailed anatomy, fantasy",
20
+ "Супергерои": "superhero style, comic book, vibrant colors, dynamic poses",
21
+ "Детская книга": "children's book style, whimsical, colorful, simple shapes",
22
+ "Готический": "gothic style, dark, intricate details, brooding atmosphere",
23
+ "Ретро": "retro style, vintage, 8-bit, nostalgic",
24
+ "Стимпанк": "steampunk style, steam-powered machinery, brass and copper elements, Victorian era",
25
+ "Фэнтези": "fantasy style, magical creatures, enchanted forests, mythical landscapes",
26
+ "Народные мотивы": "folk art style, traditional patterns, cultural motifs, vibrant colors",
27
+ "Минимализм": "minimalist style, clean lines, simple shapes, neutral colors",
28
+ "Гаражный хардкор": "garage punk style, industrial, rugged, DIY, metal textures",
29
+ "Стример": "streamer style, gaming, charismatic, energetic, modern",
30
+ "Новый хоррор": "new horror style, dark atmosphere, suspenseful, twisted, modern",
31
+ "Детская мультфильм": "children's animation style, colorful, cartoonish, simple shapes",
32
+ "Арт-ноу": "art nouveau style, ornate, flowing lines, detailed patterns",
33
+ "Викторианский": "victorian style, intricate details, ornate architecture, vintage",
34
+ "Грейский тон": "grayscale style, monochrome, detailed textures, high contrast",
35
+ "Моцарт": "mozart style, classical music, baroque, elegant, detailed",
36
+ "Гамбит": "chess style, board game, strategy, detailed pieces, high contrast",
37
+ "Киберпанк": "cyberpunk style, futuristic, neon lights, high-tech, detailed environments",
38
+ "Грот": "cave style, underground, detailed textures, stone formations, natural",
39
+ "Цирк": "circus style, vibrant, acrobatic, colorful, dynamic",
40
+ "Арт-деко": "art deco style, geometric patterns, ornate, luxurious, 1920s",
41
+ "Стратегические игры": "strategy game style, hexagonal tiles, detailed maps, military units",
42
+ "Инди-игра": "indie game style, charming, minimalist, vibrant colors, simple graphics",
43
+ "Медиевский": "medieval style, knightly armor, castles, detailed textures, historical",
44
+ "Макет": "model kit style, detailed parts, assembly instructions, high precision",
45
+ "Футуристический": "futuristic style, sleek design, high-tech, minimalistic, modern",
46
+ "Пасхалка": "easter egg style, hidden details, playful, humorous, subtle",
47
+ "Микстап": "meme style, humorous, exaggerated, pop culture references, viral",
48
+ "Скульптура": "sculpture style, detailed modeling, textured surfaces, realistic materials",
49
+ "Дизайн интерьера": "interior design style, modern, functional, detailed textures, cozy",
50
+ "Спорт": "sports style, dynamic action, detailed athletes, high contrast, vibrant colors",
51
+ "Голливудский": "hollywood style, glamour, high contrast, detailed sets, cinematic",
52
+ "Тематический парк": "theme park style, vibrant, detailed rides, futuristic, entertaining",
53
+ "Космический полет": "space travel style, detailed spaceships, planets, starfields, high contrast",
54
+ "Лабиринт": "maze style, intricate pathways, detailed textures, puzzle-like, high contrast",
55
+ "Тропический лес": "tropical rainforest style, lush vegetation, detailed textures, vibrant colors",
56
+ "Экспериментальный": "experimental style, abstract, unconventional, detailed patterns, vibrant colors"
57
+ }
58
+
59
+ prompt = style_tags.get(style, "") + " " + prompt if style_tags.get(style, "") else prompt
60
+ prompt = prompt.strip()
61
+
62
  url = f"https://image.pollinations.ai/prompt/{prompt}?width={width}&height={height}&seed={seed}&nologo=true&nofeed=true"
63
+ response = requests.get(url, timeout=150)
64
  if response.status_code == 200:
65
  return response.content
66
  else:
 
69
  # Создаем интерфейс Gradio
70
  with gr.Blocks() as demo:
71
  with gr.Tab("Основные настройки"):
72
+ prompt_input = gr.Textbox(label="Описание изображения", placeholder="Введите описание изображения на английском языке")
73
+
74
+ with gr.Accordion("Стиль", open=False):
75
+ style_radio = gr.Radio(label="Выбор стиля", choices=[
76
+ "Свой",
77
+ "Аниме",
78
+ "Реализм",
79
+ "3D",
80
+ "Краски",
81
+ "Пиксель-арт",
82
+ "Машины с лицами",
83
+ "Космический",
84
+ "Монстры",
85
+ "Супергерои",
86
+ "Детская книга",
87
+ "Готический",
88
+ "Ретро",
89
+ "Стимпанк",
90
+ "Фэнтези",
91
+ "Народные мотивы",
92
+ "Минимализм",
93
+ "Гаражный хардкор",
94
+ "Стример",
95
+ "Новый хоррор",
96
+ "Детская мультфильм",
97
+ "Арт-ноу",
98
+ "Викторианский",
99
+ "Грейский тон",
100
+ "Моцарт",
101
+ "Гамбит",
102
+ "Киберпанк",
103
+ "Грот",
104
+ "Цирк",
105
+ "Арт-деко",
106
+ "Стратегические игры",
107
+ "Инди-игра",
108
+ "Медиевский",
109
+ "Макет",
110
+ "Футуристический",
111
+ "Пасхалка",
112
+ "Микстап",
113
+ "Скульптура",
114
+ "Дизайн интерьера",
115
+ "Спорт",
116
+ "Голливудский",
117
+ "Тематический парк",
118
+ "Космический полет",
119
+ "Лабиринт",
120
+ "Тропический лес",
121
+ "Экспериментальный"
122
+ ], value="Свой")
123
 
124
  with gr.Tab("Дополнительные настройки"):
125
  width_slider = gr.Slider(label="Ширина", minimum=1, maximum=4000, value=1024)
126
+ height_slider = gr.Slider(label="Высота", minimum=1, maximum=4000, value=1024)
127
  seed_slider = gr.Slider(label="Сид", minimum=-1, maximum=999999, value=-1, step=1)
128
 
129
  create_button = gr.Button("Создать")
130
  output_image = gr.Image(label="Изображение", type="pil") # Указываем тип вывода как PIL изображение
131
 
132
+ create_button.click(fn=generate_image, inputs=[prompt_input, style_radio, width_slider, height_slider, seed_slider], outputs=output_image)
133
 
134
  demo.launch()