daveckw commited on
Commit
5acbe47
1 Parent(s): 5c9ad8f
Files changed (3) hide show
  1. .gitignore +2 -1
  2. .pylintrc +3 -1
  3. app.py +42 -17
.gitignore CHANGED
@@ -1 +1,2 @@
1
- ./outputs
 
 
1
+ outputs
2
+ flagged
.pylintrc CHANGED
@@ -1,2 +1,4 @@
1
  [pylint.messages_control]
2
- disable=W0612,W0621,C0411,W0611,C0114,C0116,W1514,C0103,W0718,W0602
 
 
 
1
  [pylint.messages_control]
2
+ disable=W0612,W0621,C0411,W0611,C0114,C0116,W1514,C0103,W0718,W0602,C0301
3
+
4
+ # Line too long (C0301)
app.py CHANGED
@@ -13,11 +13,11 @@ initial_height = 512
13
 
14
  params = {
15
  "enable_SD_api": True,
16
- "address": "https://fb9f-2001-d08-e3-41de-e9bf-9904-76d2-5584.ngrok-free.app",
17
  "save_img": True,
18
- "SD_model": "Unused", # not actually used
19
- "prompt_prefix": "4k, 8k, masterpiece, artstation, in dressed",
20
- "negative_prompt": "Naked, Nude, EasyNegative, paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans,extra fingers,fewer fingers,strange fingers,bad hand, paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (outdoor:1.6), manboobs, backlight,(ugly:1.331), (duplicate:1.331), (morbid:1.21), (mutilated:1.21), (tranny:1.331), mutated hands, (poorly drawn hands:1.331), blurry, (bad anatomy:1.21), (bad proportions:1.331), extra limbs, (disfigured:1.331), (more than 2 nipples:1.331), (missing arms:1.331), (extra legs:1.331), (fused fingers:1.61051), (too many fingers:1.61051), (unclear eyes:1.331), bad hands, missing fingers, extra digit, (futa:1.1), bad body, NG_DeepNegative_V1_75T,pubic hair, glans, paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, (outdoor:1.6), manboobs, backlight,(ugly:1.331), (duplicate:1.331), (morbid:1.21), (mutilated:1.21), (tranny:1.331), mutated hands, (poorly drawn hands:1.331), blurry, (bad anatomy:1.21), (bad proportions:1.331), extra limbs, (disfigured:1.331), (more than 2 nipples:1.331), (missing arms:1.331), (extra legs:1.331), (fused fingers:1.61051), (too many fingers:1.61051), (unclear eyes:1.331), bad hands, missing fingers, extra digit, (futa:1.1), bad body, NG_DeepNegative_V1_75T,pubic hair, glans",
21
  "width": initial_width,
22
  "height": initial_height,
23
  "restore_faces": False,
@@ -41,9 +41,15 @@ def get_SD_pictures(description):
41
  "negative_prompt": params["negative_prompt"],
42
  }
43
 
44
- response = requests.post(
45
- url=f'{params["address"]}/sdapi/v1/txt2img', json=payload, timeout=10
46
- )
 
 
 
 
 
 
47
 
48
  r = response.json()
49
 
@@ -73,21 +79,38 @@ def get_SD_pictures(description):
73
  return visible_result
74
 
75
 
76
- def display_image(description: str, kashif: bool, daniel_ho: bool) -> gr.Image:
77
- if kashif:
78
  description += " <lora:Kashif_v1:0.9>"
79
- if daniel_ho:
80
  description += " <lora:DanielHo_v1:0.9>"
81
-
82
- if kashif or daniel_ho:
83
- params["width"] = 512
84
- params["height"] = 512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  else:
86
  params["width"] = initial_width
87
  params["height"] = initial_height
 
88
 
89
  visible_result = get_SD_pictures(description)
90
- print(description)
 
 
91
  image_data = base64.b64decode(visible_result.split(",", 1)[1])
92
  image = Image.open(io.BytesIO(image_data))
93
  return image
@@ -95,8 +118,10 @@ def display_image(description: str, kashif: bool, daniel_ho: bool) -> gr.Image:
95
 
96
  inputs = [
97
  gr.inputs.Textbox(lines=2, label="Enter image description"),
98
- gr.inputs.Checkbox(label="Kashif"),
99
- gr.inputs.Checkbox(label="Daniel Ho"),
 
 
100
  ]
101
 
102
  outputs = gr.outputs.Image(type="pil", label="Generated Image")
 
13
 
14
  params = {
15
  "enable_SD_api": True,
16
+ "address": "https://253f-2001-d08-e3-5197-8959-3944-7869-3df9.ngrok-free.app",
17
  "save_img": True,
18
+ "SD_model": "Chilloutmix-Ni-prune-fp32-fix.safetensors",
19
+ "prompt_prefix": "detailed portrait of a asian man in black jacket, Futuristic sci-fi fashion, fine details, realistic shaded, fine-face, pretty face cyberpunk, neotokyo, synthwave, aesthetics, futuristic, low-emission-neon, (blade runner movie scene)",
20
+ "negative_prompt": "jpeg artifacts, low quality, lowres, 3d, render, doll, plastic, blur, haze, monochrome, b&w, text, (ugly:1.2), unclear eyes, no arms, bad anatomy, cropped, censoring, asymmetric eyes, bad anatomy, bad proportions, cropped, cross-eyed, deformed, extra arms, extra fingers, extra limbs, fused fingers, malformed, mangled hands, misshapen body, missing arms, missing fingers, missing hands, missing legs, poorly drawn, tentacle finger, too many arms, too many fingers, watermark, logo, text, letters, signature, username, words, blurry, cropped",
21
  "width": initial_width,
22
  "height": initial_height,
23
  "restore_faces": False,
 
41
  "negative_prompt": params["negative_prompt"],
42
  }
43
 
44
+ try:
45
+ response = requests.post(
46
+ url=f'{params["address"]}/sdapi/v1/txt2img', json=payload, timeout=100
47
+ )
48
+ response.raise_for_status() # Raises stored HTTPError, if one occurred
49
+ except requests.exceptions.HTTPError as http_err:
50
+ return f"HTTP error occurred: {http_err}"
51
+ except Exception as err:
52
+ return f"An error occurred: {err}"
53
 
54
  r = response.json()
55
 
 
79
  return visible_result
80
 
81
 
82
+ def display_image(description: str, artist: str) -> gr.Image:
83
+ if artist == "Kashif":
84
  description += " <lora:Kashif_v1:0.9>"
85
+ elif artist == "Daniel Ho":
86
  description += " <lora:DanielHo_v1:0.9>"
87
+ elif artist == "Adrian":
88
+ description += " <lora:AdrianSeowV1:0.9>"
89
+ elif artist == "Tony":
90
+ description += " <lora:TonyYap4:0.9>"
91
+ elif artist == "Kevin":
92
+ description += " <lora:KevinLowV1:0.9>"
93
+ elif artist == "Aaron":
94
+ description += " <lora:AaronSiowV1:0.9>"
95
+
96
+ if artist == "none":
97
+ artist = False
98
+
99
+ if artist:
100
+ params["width"] = 768
101
+ params["height"] = 768
102
+ params[
103
+ "prompt_prefix"
104
+ ] = "detailed portrait of a asian man in black jacket, Futuristic sci-fi fashion, fine details, realistic shaded, fine-face, pretty face cyberpunk, neotokyo, synthwave, aesthetics, futuristic, low-emission-neon, (blade runner movie scene)"
105
  else:
106
  params["width"] = initial_width
107
  params["height"] = initial_height
108
+ params["prompt_prefix"] = "4k"
109
 
110
  visible_result = get_SD_pictures(description)
111
+ if "error occurred" in visible_result:
112
+ return visible_result
113
+
114
  image_data = base64.b64decode(visible_result.split(",", 1)[1])
115
  image = Image.open(io.BytesIO(image_data))
116
  return image
 
118
 
119
  inputs = [
120
  gr.inputs.Textbox(lines=2, label="Enter image description"),
121
+ gr.inputs.Radio(
122
+ ["Kashif", "Daniel Ho", "Adrian", "Tony", "Kevin", "Aaron", "none"],
123
+ label="Artist",
124
+ ),
125
  ]
126
 
127
  outputs = gr.outputs.Image(type="pil", label="Generated Image")