ehristoforu commited on
Commit
66863fc
·
1 Parent(s): 2590cf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -29
app.py CHANGED
@@ -17,45 +17,21 @@ headers = {"Authorization": f"Bearer {API_TOKEN}"}
17
  word_list_dataset = load_dataset("openskyml/bad-words-prompt-list", data_files="en.txt", use_auth_token=True)
18
  word_list = word_list_dataset["train"]['text']
19
 
20
- def query(prompt, is_negative=False, image_style="None style", steps=8, cfg_scale=7, seed=None, num_images=4):
21
  for filter in word_list:
22
  if re.search(rf"\b{filter}\b", prompt):
23
  raise gr.Error("Unsafe content found. Please try again with different prompts.")
24
  images = []
 
25
  for _ in range(num_images):
26
- if image_style == "None style":
27
- payload = {
28
  "inputs": prompt + ", 8k",
29
  "is_negative": is_negative,
30
  "steps": steps,
31
  "cfg_scale": cfg_scale,
32
  "seed": seed if seed is not None else random.randint(-1, 2147483647)
33
  }
34
- elif image_style == "Cinematic":
35
- payload = {
36
- "inputs": prompt + ", realistic, detailed, textured, skin, hair, eyes, by Alex Huguet, Mike Hill, Ian Spriggs, JaeCheol Park, Marek Denko",
37
- "is_negative": is_negative + ", abstract, cartoon, stylized",
38
- "steps": steps,
39
- "cfg_scale": cfg_scale,
40
- "seed": seed if seed is not None else random.randint(-1, 2147483647)
41
- }
42
- elif image_style == "Digital Art":
43
- payload = {
44
- "inputs": prompt + ", faded , vintage , nostalgic , by Jose Villa , Elizabeth Messina , Ryan Brenizer , Jonas Peterson , Jasmine Star",
45
- "is_negative": is_negative + ", sharp , modern , bright",
46
- "steps": steps,
47
- "cfg_scale": cfg_scale,
48
- "seed": seed if seed is not None else random.randint(-1, 2147483647)
49
- }
50
- elif image_style == "Portrait":
51
- payload = {
52
- "inputs": prompt + ", soft light, sharp, exposure blend, medium shot, bokeh, (hdr:1.4), high contrast, (cinematic, teal and orange:0.85), (muted colors, dim colors, soothing tones:1.3), low saturation, (hyperdetailed:1.2), (noir:0.4), (natural skin texture, hyperrealism, soft light, sharp:1.2)",
53
- "is_negative": is_negative,
54
- "steps": steps,
55
- "cfg_scale": cfg_scale,
56
- "seed": seed if seed is not None else random.randint(-1, 2147483647)
57
- }
58
-
59
  image_bytes = requests.post(API_URL, headers=headers, json=payload).content
60
  image = Image.open(io.BytesIO(image_bytes))
61
 
@@ -212,8 +188,10 @@ with gr.Blocks(css=css) as demo:
212
  with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
213
  with gr.Column():
214
  gallery_output = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
 
 
215
  text_prompt = gr.Textbox(show_label=False, placeholder="Enter your prompt", max_lines=1, elem_id="prompt-text-input").style(border=(True, False, True, True), rounded=(True, False, False, True), container=False)
216
- negative_prompt = gr.Textbox(show_label=False, placeholder="Enter a negative prompt", max_lines=1, elem_id="negative-prompt-text-input").style(border=(True, False, True, True), rounded=(True, False, False, True), container=False)
217
  text_button = gr.Button("Generate").style(margin=False, rounded=(False, True, True, False), full_width=False)
218
 
219
 
 
17
  word_list_dataset = load_dataset("openskyml/bad-words-prompt-list", data_files="en.txt", use_auth_token=True)
18
  word_list = word_list_dataset["train"]['text']
19
 
20
+ def query(prompt, is_negative=False, steps=7, cfg_scale=7, seed=None, num_images=4):
21
  for filter in word_list:
22
  if re.search(rf"\b{filter}\b", prompt):
23
  raise gr.Error("Unsafe content found. Please try again with different prompts.")
24
  images = []
25
+
26
  for _ in range(num_images):
27
+ payload = {
 
28
  "inputs": prompt + ", 8k",
29
  "is_negative": is_negative,
30
  "steps": steps,
31
  "cfg_scale": cfg_scale,
32
  "seed": seed if seed is not None else random.randint(-1, 2147483647)
33
  }
34
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  image_bytes = requests.post(API_URL, headers=headers, json=payload).content
36
  image = Image.open(io.BytesIO(image_bytes))
37
 
 
188
  with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
189
  with gr.Column():
190
  gallery_output = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
191
+ with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
192
+ with gr.Column():
193
  text_prompt = gr.Textbox(show_label=False, placeholder="Enter your prompt", max_lines=1, elem_id="prompt-text-input").style(border=(True, False, True, True), rounded=(True, False, False, True), container=False)
194
+ negative_prompt = gr.Textbox(show_label=False, placeholder="Enter a negative", max_lines=1, elem_id="negative-prompt-text-input").style(border=(True, False, True, True), rounded=(True, False, False, True), container=False)
195
  text_button = gr.Button("Generate").style(margin=False, rounded=(False, True, True, False), full_width=False)
196
 
197