Nymbo commited on
Commit
6f5a32e
1 Parent(s): e547b24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -23
app.py CHANGED
@@ -10,13 +10,13 @@ import json
10
 
11
  # Project by Nymbo
12
 
13
- API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl"
14
  API_TOKEN = os.getenv("HF_READ_TOKEN")
15
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
16
  timeout = 100
17
 
18
  def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
19
- if prompt == "" or prompt is None:
20
  return None
21
 
22
  key = random.randint(0, 999)
@@ -25,10 +25,10 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
25
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
26
 
27
  prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
28
- print(f'\033[1mГенерация {key} перевод:\033[0m {prompt}')
29
 
30
  prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
31
- print(f'\033[1mГенерация {key}:\033[0m {prompt}')
32
 
33
  payload = {
34
  "inputs": prompt,
@@ -41,20 +41,19 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
41
 
42
  response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
43
  if response.status_code != 200:
44
- print(f"Ошибка: Не удалось получить изображение. Статус ответа: {response.status_code}")
45
- print(f"Содержимое ответа: {response.text}")
46
  if response.status_code == 503:
47
  raise gr.Error(f"{response.status_code} : The model is being loaded")
48
  raise gr.Error(f"{response.status_code}")
49
- return None
50
 
51
  try:
52
  image_bytes = response.content
53
  image = Image.open(io.BytesIO(image_bytes))
54
- print(f'\033[1mГенерация {key} завершена!\033[0m ({prompt})')
55
  return image
56
  except Exception as e:
57
- print(f"Ошибка при попытке открыть изображение: {e}")
58
  return None
59
 
60
  css = """
@@ -62,27 +61,77 @@ css = """
62
  footer {visibility: hidden !important;}
63
  """
64
 
65
- with gr.Blocks(theme='Nymbo/Nymbo_Theme') as dalle:
66
  with gr.Tab("Basic Settings"):
67
  with gr.Row():
68
  with gr.Column(elem_id="prompt-container"):
69
  with gr.Row():
70
  text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
 
 
 
 
 
 
 
 
71
 
72
- with gr.Tab("Advanced Settings"):
73
- with gr.Accordion("Advanced Settings", open=True):
74
- with gr.Row():
75
- 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")
76
- with gr.Row():
77
- steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
78
- with gr.Row():
79
- cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
80
- with gr.Row():
81
- method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
82
- with gr.Row():
83
- strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
84
  with gr.Row():
85
- seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  with gr.Row():
88
  text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
 
10
 
11
  # Project by Nymbo
12
 
13
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
14
  API_TOKEN = os.getenv("HF_READ_TOKEN")
15
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
16
  timeout = 100
17
 
18
  def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
19
+ if prompt == "" or prompt == None:
20
  return None
21
 
22
  key = random.randint(0, 999)
 
25
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
26
 
27
  prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
28
+ print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
29
 
30
  prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
31
+ print(f'\033[1mGeneration {key}:\033[0m {prompt}')
32
 
33
  payload = {
34
  "inputs": prompt,
 
41
 
42
  response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
43
  if response.status_code != 200:
44
+ print(f"Error: Failed to get image. Response status: {response.status_code}")
45
+ print(f"Response content: {response.text}")
46
  if response.status_code == 503:
47
  raise gr.Error(f"{response.status_code} : The model is being loaded")
48
  raise gr.Error(f"{response.status_code}")
 
49
 
50
  try:
51
  image_bytes = response.content
52
  image = Image.open(io.BytesIO(image_bytes))
53
+ print(f'\033[1mGeneration {key} completed!\033[0m ({prompt})')
54
  return image
55
  except Exception as e:
56
+ print(f"Error when trying to open the image: {e}")
57
  return None
58
 
59
  css = """
 
61
  footer {visibility: hidden !important;}
62
  """
63
 
64
+ with gr.Blocks(theme='Nymbo/Alyx_Theme') as dalle:
65
  with gr.Tab("Basic Settings"):
66
  with gr.Row():
67
  with gr.Column(elem_id="prompt-container"):
68
  with gr.Row():
69
  text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
70
+ with gr.Row():
71
+ with gr.Accordion("Advanced Settings", open=False):
72
+ 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")
73
+ steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
74
+ cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
75
+ method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
76
+ strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
77
+ seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
78
 
79
+ with gr.Tab("Image Editor"):
80
+ def sleep(im):
81
+ time.sleep(5)
82
+ return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
83
+
84
+ def predict(im):
85
+ return im["composite"]
86
+
87
+ with gr.Blocks() as demo:
 
 
 
88
  with gr.Row():
89
+ im = gr.ImageEditor(
90
+ type="numpy",
91
+ crop_size="1:1",
92
+ )
93
+
94
+ with gr.Tab("Information"):
95
+ with gr.Row():
96
+ gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
97
+
98
+ with gr.Accordion("Advanced Settings Overview", open=False):
99
+ gr.Markdown(
100
+ """ # `Alyxsissy.com`
101
+ ## Negative Prompt
102
+ ###### This box is for telling the AI what you don't want in your images. Think of it as a way to avoid certain elements. For instance, if you don't want blurry images or extra limbs showing up, this is where you'd mention it.
103
+
104
+ ## Sampling Steps
105
+ ###### Think of this like the number of brushstrokes in a painting. A higher number can give you a more detailed picture, but it also takes a bit longer. Generally, a middle-ground number like 35 is a good balance between quality and speed.
106
+
107
+ ## CFG Scale
108
+ ###### CFG stands for "Control Free Guidance." The scale adjusts how closely the AI follows your prompt. A lower number makes the AI more creative and free-flowing, while a higher number makes it stick closely to what you asked for. If you want the AI to take fewer artistic liberties, slide this towards a higher number. Just think "Control Freak Gauge".
109
+
110
+ ## Sampling Method
111
+ ###### This is the technique the AI uses to create your image. Each option is a different approach, like choosing between pencils, markers, or paint. You don't need to worry too much about this; the default setting is usually the best choice for most users.
112
+
113
+ ## Strength
114
+ ###### This setting is a bit like the 'intensity' knob. It determines how much the AI modifies the base image it starts with. If you're looking to make subtle changes, keep this low. For more drastic transformations, turn it up.
115
+
116
+ ## Seed
117
+ ###### You can think of the seed as a 'recipe' for creating an image. If you find a seed that gives you a result you love, you can use it again to create a similar image. If you leave it at -1, the AI will generate a new seed every time.
118
+
119
+
120
+ ### Remember, these settings are all about giving you control over the image generation process. Feel free to experiment and see what each one does. And if you're ever in doubt, the default settings are a great place to start. Happy creating!
121
+ """
122
+ )
123
+
124
+ with gr.Accordion("Error Codes and What They Mean", open=False):
125
+ gr.Markdown(
126
+ """ # `Alyxsissy.com`
127
+ ## Error Codes:
128
+ #### 500: Error Fetching Model
129
+ ###### This is a temporary error usually caused by a model experiencing high demand, or it is being updated. Try again in a few minutes.
130
+
131
+ #### 503: Model is being loaded
132
+ ###### When a particular model hasn't been used for some time, it goes into sleep mode. Error 503 means that the model is being loaded and will be ready within a minute.
133
+ """
134
+ )
135
 
136
  with gr.Row():
137
  text_button = gr.Button("Run", variant='primary', elem_id="gen-button")