Rooni commited on
Commit
713d510
1 Parent(s): ee3af61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -10
app.py CHANGED
@@ -13,14 +13,14 @@ headers = {"Authorization": f"Bearer {API_TOKEN}"}
13
 
14
  models_list = ["AbsoluteReality 1.8.1", "DALL-E 3 XL", "Playground 2", "Openjourney 4", "Lyriel 1.6", "Animagine XL 2.0", "Counterfeit 2.5", "Realistic Vision 5.1", "Incursios 1.6", "Anime Detailer XL LoRA", "epiCRealism", "PixelArt XL", "NewReality XL"]
15
 
16
- def query(prompt, model, width, height, is_negative=False, steps=20, cfg_scale=7, seed=None):
17
  language = detect(prompt)
18
  key = random.randint(0, 999)
19
 
20
  print(f'\033[1mГенерация {key}:\033[0m {prompt}')
21
  if language == 'ru':
22
  prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
23
- print(f'\033[1mГенерация {key} перевод:\033[0m {prompt}')
24
 
25
  if model == 'DALL-E 3 XL':
26
  API_URL = "https://api-inference.huggingface.co/models/openskyml/dalle-3-xl"
@@ -48,15 +48,13 @@ def query(prompt, model, width, height, is_negative=False, steps=20, cfg_scale=7
48
  API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
49
  if model == 'NewReality XL':
50
  API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/newrealityxl-global-nsfw"
51
-
52
  payload = {
53
  "inputs": prompt,
54
  "is_negative": is_negative,
55
  "steps": steps,
56
  "cfg_scale": cfg_scale,
57
- "seed": seed if seed is not None else random.randint(-1, 2147483647),
58
- "output_width": width,
59
- "output_height": height
60
  }
61
 
62
  image_bytes = requests.post(API_URL, headers=headers, json=payload).content
@@ -78,15 +76,12 @@ with gr.Blocks(css=css) as dalle:
78
 
79
  with gr.Tab("Расширенные настройки"):
80
  negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Чего не должно быть на изображении", value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry, text, fuzziness", lines=3, elem_id="negative-prompt-text-input")
81
- width = gr.Slider(label="Ширина", value=512, minimum=15, maximum=1023)
82
- height = gr.Slider(label="Высота", value=512, minimum=15, maximum=1023)
83
-
84
 
85
  with gr.Row():
86
  text_button = gr.Button("Генерация", variant='primary', elem_id="gen-button")
87
  with gr.Row():
88
  image_output = gr.Image(type="pil", label="Изображение", elem_id="gallery")
89
 
90
- text_button.click(query, inputs=[text_prompt, model, width, height, negative_prompt], outputs=image_output)
91
 
92
  dalle.launch(show_api=False)
 
13
 
14
  models_list = ["AbsoluteReality 1.8.1", "DALL-E 3 XL", "Playground 2", "Openjourney 4", "Lyriel 1.6", "Animagine XL 2.0", "Counterfeit 2.5", "Realistic Vision 5.1", "Incursios 1.6", "Anime Detailer XL LoRA", "epiCRealism", "PixelArt XL", "NewReality XL"]
15
 
16
+ def query(prompt, model, is_negative=False, steps=20, cfg_scale=7, seed=None):
17
  language = detect(prompt)
18
  key = random.randint(0, 999)
19
 
20
  print(f'\033[1mГенерация {key}:\033[0m {prompt}')
21
  if language == 'ru':
22
  prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
23
+ print(f'\033[1mГенерация {key} перевод:\033[0m {prompt}')
24
 
25
  if model == 'DALL-E 3 XL':
26
  API_URL = "https://api-inference.huggingface.co/models/openskyml/dalle-3-xl"
 
48
  API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
49
  if model == 'NewReality XL':
50
  API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/newrealityxl-global-nsfw"
51
+
52
  payload = {
53
  "inputs": prompt,
54
  "is_negative": is_negative,
55
  "steps": steps,
56
  "cfg_scale": cfg_scale,
57
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
 
 
58
  }
59
 
60
  image_bytes = requests.post(API_URL, headers=headers, json=payload).content
 
76
 
77
  with gr.Tab("Расширенные настройки"):
78
  negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Чего не должно быть на изображении", value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry, text, fuzziness", lines=3, elem_id="negative-prompt-text-input")
 
 
 
79
 
80
  with gr.Row():
81
  text_button = gr.Button("Генерация", variant='primary', elem_id="gen-button")
82
  with gr.Row():
83
  image_output = gr.Image(type="pil", label="Изображение", elem_id="gallery")
84
 
85
+ text_button.click(query, inputs=[text_prompt, model, negative_prompt], outputs=image_output)
86
 
87
  dalle.launch(show_api=False)