lalashechka commited on
Commit
12c3b25
1 Parent(s): 6735637

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -45
app.py CHANGED
@@ -15,36 +15,65 @@ from gradio_client import Client
15
 
16
 
17
  def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
18
- headers = {
19
- 'authority': 'multimodalart-stable-cascade.hf.space',
20
- 'accept': 'text/event-stream',
21
- 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
22
- 'cache-control': 'no-cache',
23
- 'referer': 'https://multimodalart-stable-cascade.hf.space/?__theme=light',
24
- 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
25
- 'sec-ch-ua-mobile': '?0',
26
- 'sec-ch-ua-platform': '"Windows"',
27
- 'sec-fetch-dest': 'empty',
28
- 'sec-fetch-mode': 'cors',
29
- 'sec-fetch-site': 'same-origin',
30
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 YaBrowser/24.1.0.0 Safari/537.36',
31
- }
32
- client = Client("multimodalart/stable-cascade", headers=headers)
33
- result = client.predict(
34
- "cat!!", # str in 'Prompt' Textbox component
35
- "", # str in 'Negative prompt' Textbox component
36
- 0, # float (numeric value between 0 and 2147483647) in 'Seed' Slider component
37
- 1024, # float (numeric value between 1024 and 1536) in 'Width' Slider component
38
- 1024, # float (numeric value between 1024 and 1536) in 'Height' Slider component
39
- 20, # float (numeric value between 10 and 30) in 'Prior Inference Steps' Slider component
40
- 4, # float (numeric value between 0 and 20) in 'Prior Guidance Scale' Slider component
41
- 10, # float (numeric value between 4 and 12) in 'Decoder Inference Steps' Slider component
42
- 0, # float (numeric value between 0 and 0) in 'Decoder Guidance Scale' Slider component
43
- 1, # float (numeric value between 1 and 2) in 'Number of Images' Slider component
44
-
45
- api_name="/run"
46
- )
47
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
 
50
  def mirror(image_output, scale_by, method, gfpgan, codeformer):
@@ -96,23 +125,10 @@ with gr.Blocks(css=css) as demo:
96
  with gr.Tab("Базовые настройки"):
97
  with gr.Row():
98
  prompt = gr.Textbox(placeholder="Введите описание изображения...", show_label=True, label='Описание изображения:', lines=3)
99
- with gr.Row():
100
- task = gr.Radio(interactive=True, value="Stable Diffusion XL 1.0", show_label=True, label="Модель нейросети:", choices=['Stable Diffusion XL 1.0', 'Crystal Clear XL',
101
- 'Juggernaut XL', 'DreamShaper XL',
102
- 'SDXL Niji', 'Cinemax SDXL', 'NightVision XL',
103
- 'Playground v2', 'OpenDalle v1.1'])
104
  with gr.Tab("Расширенные настройки"):
105
  with gr.Row():
106
  negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=True, label='Negative Prompt:', lines=3, value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry")
107
- with gr.Row():
108
- sampler = gr.Dropdown(value="DPM++ SDE Karras", show_label=True, label="Sampling Method:", choices=[
109
- "Euler", "Euler a", "Heun", "DPM++ 2M", "DPM++ SDE", "DPM++ 2M Karras", "DPM++ SDE Karras", "DDIM"])
110
- with gr.Row():
111
- steps = gr.Slider(show_label=True, label="Sampling Steps:", minimum=1, maximum=50, value=35, step=1)
112
- with gr.Row():
113
- cfg_scale = gr.Slider(show_label=True, label="CFG Scale:", minimum=1, maximum=20, value=7, step=1)
114
- with gr.Row():
115
- seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
116
 
117
  with gr.Tab("Настройки апскейлинга"):
118
  with gr.Column():
@@ -130,7 +146,7 @@ with gr.Blocks(css=css) as demo:
130
  text_button = gr.Button("Сгенерировать изображение", variant='primary', elem_id="generate")
131
  with gr.Column():
132
  image_output = gr.Image(show_download_button=True, interactive=False, label='Результат:', elem_id='image_output', type='filepath')
133
- text_button.click(flip_text, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output, concurrency_limit=12)
134
 
135
  img2img_b = gr.Button("Увеличить изображение", variant='secondary')
136
  image_i2i = gr.Image(show_label=True, label='Увеличенное изображение:')
 
15
 
16
 
17
  def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
18
+ prompt = re.sub(r'[^a-zA-Zа-яА-Я\s]', '', prompt)
19
+
20
+ try:
21
+ language = detect(prompt)
22
+ if language == 'ru':
23
+ prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
24
+ print(prompt)
25
+ except:
26
+ pass
27
+
28
+ try:
29
+ with closing(create_connection(f"wss://artgan-diffusion-api.hf.space/queue/join", timeout=60)) as conn:
30
+ conn.send('{"fn_index":0,"session_hash":""}')
31
+ conn.send(f'{{"fn_index":0,"data":["{prompt}",{negative_prompt},1024,1024,4,42,1,20,10],"session_hash":""}}')
32
+ conn.recv()
33
+ conn.recv()
34
+ conn.recv()
35
+ conn.recv()
36
+ a = conn.recv()
37
+ photo = json.loads(a)['output']['data'][0][0]['name']
38
+ photo = "https://artgan-diffusion-api.hf.space/file=" + photo
39
+ return photo
40
+ except:
41
+ try:
42
+ headers = {
43
+ 'authority': 'ehristoforu-stable-cascade.hf.space',
44
+ 'accept': 'text/event-stream',
45
+ 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
46
+ 'cache-control': 'no-cache',
47
+ 'referer': 'https://ehristoforu-stable-cascade.hf.space/?__theme=light',
48
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
49
+ 'sec-ch-ua-mobile': '?0',
50
+ 'sec-ch-ua-platform': '"Windows"',
51
+ 'sec-fetch-dest': 'empty',
52
+ 'sec-fetch-mode': 'cors',
53
+ 'sec-fetch-site': 'same-origin',
54
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 YaBrowser/24.1.0.0 Safari/537.36',
55
+ }
56
+ client = Client("https://ehristoforu-stable-cascade.hf.space", headers=headers)
57
+ result = client.predict(prompt, negative_prompt, 1024, 1024, True)
58
+ return result[0]['image']
59
+ except:
60
+ headers = {
61
+ 'authority': 'multimodalart-stable-cascade.hf.space',
62
+ 'accept': 'text/event-stream',
63
+ 'accept-language': 'ru,en;q=0.9,la;q=0.8,ja;q=0.7',
64
+ 'cache-control': 'no-cache',
65
+ 'referer': 'https://multimodalart-stable-cascade.hf.space/?__theme=light',
66
+ 'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "YaBrowser";v="24.1", "Yowser";v="2.5"',
67
+ 'sec-ch-ua-mobile': '?0',
68
+ 'sec-ch-ua-platform': '"Windows"',
69
+ 'sec-fetch-dest': 'empty',
70
+ 'sec-fetch-mode': 'cors',
71
+ 'sec-fetch-site': 'same-origin',
72
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 YaBrowser/24.1.0.0 Safari/537.36',
73
+ }
74
+ client = Client("multimodalart/stable-cascade", headers=headers)
75
+ result = client.predict(prompt, negative_prompt,seed, 1024, 1024, 20, 4, 10, 0, 1, api_name="/run")
76
+ return result
77
 
78
 
79
  def mirror(image_output, scale_by, method, gfpgan, codeformer):
 
125
  with gr.Tab("Базовые настройки"):
126
  with gr.Row():
127
  prompt = gr.Textbox(placeholder="Введите описание изображения...", show_label=True, label='Описание изображения:', lines=3)
 
 
 
 
 
128
  with gr.Tab("Расширенные настройки"):
129
  with gr.Row():
130
  negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=True, label='Negative Prompt:', lines=3, value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry")
131
+ seed = gr.Number(show_label=True, label="Seed:", minimum=1, maximum=1000000, value=1, step=1)
 
 
 
 
 
 
 
 
132
 
133
  with gr.Tab("Настройки апскейлинга"):
134
  with gr.Column():
 
146
  text_button = gr.Button("Сгенерировать изображение", variant='primary', elem_id="generate")
147
  with gr.Column():
148
  image_output = gr.Image(show_download_button=True, interactive=False, label='Результат:', elem_id='image_output', type='filepath')
149
+ text_button.click(flip_text, inputs=[prompt, negative_prompt, seed], outputs=image_output, concurrency_limit=12)
150
 
151
  img2img_b = gr.Button("Увеличить изображение", variant='secondary')
152
  image_i2i = gr.Image(show_label=True, label='Увеличенное изображение:')