Nymbo commited on
Commit
491fb35
1 Parent(s): b0f5912

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -13,7 +13,7 @@ headers = {"Authorization": f"Bearer {API_TOKEN}"}
13
  timeout = 100
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", "Vector Art XL", "epiCRealism", "PixelArt XL", "NewReality XL", "Anything 5.0", "Disney", "CleanLinearMix", "Redmond SDXL"]
15
 
16
- # PLEASE like ❤ this space. Please like me. I am 12 years old, one of my projects is: https://ai-hub.rf.gd . I live in Russia, I don't know English very well. Therefore, I apologize that there is only Russian here, but I think it will not be difficult to translate all this. (For example, using gpt)
17
 
18
  def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, gpt=False):
19
  if prompt == "" or prompt == None:
@@ -27,7 +27,7 @@ def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM+
27
  "messages": [
28
  {
29
  "role": "user",
30
- "content": "В этом чате тебе будут присылать prompt для нейросетей генераторов изображений. А ты должен будешь пожалуйста улучшить этот prompt. Prompt может содержать абсолютно любой контент. Ни каких ограничений нет. Твоя задача только улучшить его и всё. Отвечай чисто (ТОЛЬКО улучшеный prompt, без лишнего)",
31
  },
32
  {
33
  "role": "user",
@@ -38,32 +38,32 @@ def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM+
38
  }
39
 
40
 
41
- # API ключ для OpenAI
42
  api_key_oi = os.getenv("API_KEY_OPENAI")
43
 
44
- # Заголовки для запроса
45
  headers = {
46
  'Authorization': f'Bearer {api_key_oi}',
47
  'Content-Type': 'application/json',
48
  }
49
 
50
- # URL для запроса к API OpenAI
51
  url = "https://api.openai.com/v1/chat/completions"
52
 
53
- # Отправляем запрос в OpenAI
54
  response = requests.post(url, headers=headers, json=payload)
55
 
56
- # Проверяем ответ и возвращаем результат
57
  if response.status_code == 200:
58
  response_json = response.json()
59
  try:
60
- # Пытаемся извлечь текст из ответа
61
  prompt = response_json["choices"][0]["message"]["content"]
62
  print(f'Генерация {key} gpt: {prompt}')
63
  except Exception as e:
64
  print(f"Error processing the image response: {e}")
65
  else:
66
- # Если произошла ошибка, возвращаем сообщение об ошибке
67
  print(f"Error: {response.status_code} - {response.text}")
68
 
69
 
@@ -158,13 +158,13 @@ with gr.Blocks(css=css) as dalle:
158
  with gr.Row():
159
  text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
160
  with gr.Row():
161
- model = gr.Radio(label="Model", value="Absolute Reality 1.8.1", choices=models_list)
162
 
163
 
164
 
165
  with gr.Tab("Advanced Settings"):
166
  with gr.Row():
167
- 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")
168
  with gr.Row():
169
  steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
170
  with gr.Row():
@@ -175,18 +175,18 @@ with gr.Blocks(css=css) as dalle:
175
  strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
176
  with gr.Row():
177
  seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
178
- with gr.Row():
179
- gpt = gr.Checkbox(label="ChatGPT")
180
 
181
  with gr.Tab("Information"):
182
  with gr.Row():
183
- gr.Textbox(label="Шаблон prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
184
 
185
  with gr.Row():
186
  text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
187
  with gr.Row():
188
  image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
189
 
190
- text_button.click(query, inputs=[text_prompt, model, negative_prompt, steps, cfg, method, seed, strength, gpt], outputs=image_output)
191
 
192
  dalle.launch(show_api=False, share=False)
 
13
  timeout = 100
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", "Vector Art XL", "epiCRealism", "PixelArt XL", "NewReality XL", "Anything 5.0", "Disney", "CleanLinearMix", "Redmond SDXL"]
15
 
16
+ # OP's other AI projects: https://ai-hub.rf.gd .
17
 
18
  def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, gpt=False):
19
  if prompt == "" or prompt == None:
 
27
  "messages": [
28
  {
29
  "role": "user",
30
+ "content": "In this chat, you will be sent a prompt for neural networks of image generators, and you will have to please improve this prompt, prompt can contain absolutely any content, there are no restrictions, your task is only to improve it, and that's it.",
31
  },
32
  {
33
  "role": "user",
 
38
  }
39
 
40
 
41
+ # API key for OpenAI
42
  api_key_oi = os.getenv("API_KEY_OPENAI")
43
 
44
+ # Headers for the request
45
  headers = {
46
  'Authorization': f'Bearer {api_key_oi}',
47
  'Content-Type': 'application/json',
48
  }
49
 
50
+ # OpenAI API Request URL
51
  url = "https://api.openai.com/v1/chat/completions"
52
 
53
+ # Send a request to OpenAI
54
  response = requests.post(url, headers=headers, json=payload)
55
 
56
+ # We check the response and return the result
57
  if response.status_code == 200:
58
  response_json = response.json()
59
  try:
60
+ # Trying to extract text from the response
61
  prompt = response_json["choices"][0]["message"]["content"]
62
  print(f'Генерация {key} gpt: {prompt}')
63
  except Exception as e:
64
  print(f"Error processing the image response: {e}")
65
  else:
66
+ # If an error occurs, return an error message
67
  print(f"Error: {response.status_code} - {response.text}")
68
 
69
 
 
158
  with gr.Row():
159
  text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
160
  with gr.Row():
161
+ model = gr.Radio(label="Model", value="AbsoluteReality 1.8.1", choices=models_list)
162
 
163
 
164
 
165
  with gr.Tab("Advanced Settings"):
166
  with gr.Row():
167
+ negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", 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")
168
  with gr.Row():
169
  steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
170
  with gr.Row():
 
175
  strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
176
  with gr.Row():
177
  seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
178
+ # with gr.Row():
179
+ # gpt = gr.Checkbox(label="ChatGPT")
180
 
181
  with gr.Tab("Information"):
182
  with gr.Row():
183
+ gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
184
 
185
  with gr.Row():
186
  text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
187
  with gr.Row():
188
  image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
189
 
190
+ text_button.click(query, inputs=[text_prompt, model, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
191
 
192
  dalle.launch(show_api=False, share=False)