Spaces:
Running
Running
lalashechka
commited on
Commit
·
8b1029b
1
Parent(s):
5b6c0ab
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import time
|
4 |
+
import json
|
5 |
+
from contextlib import closing
|
6 |
+
from websocket import create_connection
|
7 |
+
from deep_translator import GoogleTranslator
|
8 |
+
from langdetect import detect
|
9 |
+
import os
|
10 |
+
from PIL import Image
|
11 |
+
import io
|
12 |
+
import base64
|
13 |
+
|
14 |
+
|
15 |
+
def flip_text(prompt, negative_prompt, task, steps, sampler, cfg_scale, seed):
|
16 |
+
result = {"prompt": prompt,"negative_prompt": negative_prompt,"task": task,"steps": steps,"sampler": sampler,"cfg_scale": cfg_scale,"seed": seed}
|
17 |
+
print(result)
|
18 |
+
|
19 |
+
language = detect(prompt)
|
20 |
+
|
21 |
+
if language == 'ru':
|
22 |
+
prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
23 |
+
print(prompt)
|
24 |
+
|
25 |
+
cfg = int(cfg_scale)
|
26 |
+
steps = int(steps)
|
27 |
+
seed = int(seed)
|
28 |
+
url_sd1 = os.getenv("url_sd1")
|
29 |
+
url_sd2 = os.getenv("url_sd2")
|
30 |
+
url_sd3 = os.getenv("url_sd3")
|
31 |
+
|
32 |
+
if task == 'Realistic Vision 5.0':
|
33 |
+
model = 'Realistic_Vision_V5.0.safetensors+%5B614d1063%5D'
|
34 |
+
if task == 'Dreamshaper 8':
|
35 |
+
model = 'dreamshaper_8.safetensors+%5B9d40847d%5D'
|
36 |
+
if task == 'Deliberate 3':
|
37 |
+
model = 'deliberate_v3.safetensors+%5Bafd9d2d4%5D'
|
38 |
+
if task == 'Analog Diffusion':
|
39 |
+
model = 'analog-diffusion-1.0.ckpt+%5B9ca13f02%5D'
|
40 |
+
if task == 'Lyriel 1.6':
|
41 |
+
model = 'lyriel_v16.safetensors+%5B68fceea2%5D'
|
42 |
+
if task == "Elldreth's Vivid Mix":
|
43 |
+
model = 'elldreths-vivid-mix.safetensors+%5B342d9d26%5D'
|
44 |
+
if task == 'Anything V5':
|
45 |
+
model = 'anything-v4.5-pruned.ckpt+%5B65745d25%5D'
|
46 |
+
if task == 'Openjourney V4':
|
47 |
+
model = 'openjourney_V4.ckpt+%5Bca2f377f%5D'
|
48 |
+
if task == 'AbsoluteReality 1.8.1':
|
49 |
+
model = 'absolutereality_v181.safetensors+%5B3d9d4d2b%5D'
|
50 |
+
if task == 'epiCRealism v5':
|
51 |
+
model = 'epicrealism_naturalSinRC1VAE.safetensors+%5B90a4c676%5D'
|
52 |
+
if task == 'CyberRealistic 3.3':
|
53 |
+
model = 'cyberrealistic_v33.safetensors+%5B82b0d085%5D'
|
54 |
+
if task == 'ToonYou 6':
|
55 |
+
model = 'toonyou_beta6.safetensors+%5B980f6b15%5D'
|
56 |
+
|
57 |
+
c = 0
|
58 |
+
r = requests.get(f'{url_sd1}{prompt}&model={model}&negative_prompt={negative_prompt}&steps={steps}&cfg={cfg}&seed={seed}&sampler={sampler}&aspect_ratio=square', timeout=10)
|
59 |
+
job = r.json()['job']
|
60 |
+
while c < 10:
|
61 |
+
c += 1
|
62 |
+
time.sleep(2)
|
63 |
+
r2 = requests.get(f'{url_sd2}{job}', timeout=10)
|
64 |
+
status = r2.json()['status']
|
65 |
+
if status == 'succeeded':
|
66 |
+
photo = f'{url_sd1}{job}.png'
|
67 |
+
return photo
|
68 |
+
if status == "queued":
|
69 |
+
continue
|
70 |
+
if status == 'failed':
|
71 |
+
return None
|
72 |
+
|
73 |
+
css = """
|
74 |
+
#generate {
|
75 |
+
width: 100%;
|
76 |
+
background: #e253dd !important;
|
77 |
+
border: none;
|
78 |
+
border-radius: 50px;
|
79 |
+
outline: none !important;
|
80 |
+
color: white;
|
81 |
+
}
|
82 |
+
#generate:hover {
|
83 |
+
background: #de6bda !important;
|
84 |
+
outline: none !important;
|
85 |
+
color: #fff;
|
86 |
+
}
|
87 |
+
footer {visibility: hidden !important;}
|
88 |
+
"""
|
89 |
+
|
90 |
+
with gr.Blocks(css=css) as demo:
|
91 |
+
|
92 |
+
with gr.Tab("Базовые настройки"):
|
93 |
+
with gr.Row():
|
94 |
+
prompt = gr.Textbox(placeholder="Введите описание изображения...", show_label=True, label='Описание изображения:', lines=3)
|
95 |
+
with gr.Row():
|
96 |
+
task = gr.Radio(interactive=True, value="Deliberate 3", show_label=True, label="Модель нейросети:",
|
97 |
+
choices=["AbsoluteReality 1.8.1", "Elldreth's Vivid Mix", "Anything V5", "Openjourney V4", "Analog Diffusion",
|
98 |
+
"Lyriel 1.6", "Realistic Vision 5.0", "Dreamshaper 8", "epiCRealism v5",
|
99 |
+
"CyberRealistic 3.3", "ToonYou 6", "Deliberate 3"])
|
100 |
+
with gr.Tab("Расширенные настройки"):
|
101 |
+
with gr.Row():
|
102 |
+
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")
|
103 |
+
with gr.Row():
|
104 |
+
sampler = gr.Dropdown(value="DPM++ SDE Karras", show_label=True, label="Sampling Method:", choices=[
|
105 |
+
"Euler", "Euler a", "Heun", "DPM++ 2M Karras", "DPM++ SDE Karras", "DDIM"])
|
106 |
+
with gr.Row():
|
107 |
+
steps = gr.Slider(show_label=True, label="Sampling Steps:", minimum=1, maximum=30, value=25, step=1)
|
108 |
+
with gr.Row():
|
109 |
+
cfg_scale = gr.Slider(show_label=True, label="CFG Scale:", minimum=1, maximum=20, value=7, step=1)
|
110 |
+
with gr.Row():
|
111 |
+
seed = gr.Number(show_label=True, label="Seed:", minimum=-1, maximum=1000000, value=-1, step=1)
|
112 |
+
with gr.Column():
|
113 |
+
text_button = gr.Button("Сгенерировать изображение", variant='primary', elem_id="generate")
|
114 |
+
with gr.Column(scale=2):
|
115 |
+
image_output = gr.Image(show_label=True, label='Результат:', elem_id='image_output')
|
116 |
+
|
117 |
+
text_button.click(flip_text, inputs=[prompt, negative_prompt, task, steps, sampler, cfg_scale, seed], outputs=image_output)
|
118 |
+
|
119 |
+
demo.queue(concurrency_count=12)
|
120 |
+
demo.launch()
|