kumahiyo commited on
Commit
f44af0a
1 Parent(s): 0c8f446

add seed and guidance scale

Browse files
Files changed (1) hide show
  1. main.py +13 -3
main.py CHANGED
@@ -1,6 +1,8 @@
1
  import os
2
  import time
3
  import sys
 
 
4
  import torch
5
  from fastapi import FastAPI
6
  from fastapi.staticfiles import StaticFiles
@@ -27,8 +29,15 @@ def draw(data: Data):
27
  if data.member_secret != "" and data.member_secret == os.environ.get("MEMBER_SECRET"):
28
  print(f"Is CUDA available: {torch.cuda.is_available()}")
29
 
30
- # prompt = '(('+data.string+')) (( photograph )), highly detailed, sharp focus, 8k, 4k, (( photorealism )), detailed, saturated, portrait, 50mm, F/2.8, 1m away, ( global illumination, studio light, volumetric light ), ((( multicolor lights )))'
31
- prompt = '(('+data.string+')) (( photograph )), highly detailed, sharp focus, 8k, 4k, (( photorealism )), detailed, saturated, portrait, 50mm, F/2.8, 1m away, ((( multicolor lights )))'
 
 
 
 
 
 
 
32
  n_prompt = 'text, blurry, art, painting, rendering, drawing, sketch, (( ugly )), (( duplicate )), ( morbid ), (( mutilated )), ( mutated ), ( deformed ), ( disfigured ), ( extra limbs ), ( malformed limbs ), ( missing arms ), ( missing legs ), ( extra arms ), ( extra legs ), ( fused fingers ), ( too many fingers ), long neck, low quality, worst quality'
33
 
34
  # https://huggingface.co/docs/hub/spaces-sdks-docker-first-demo
@@ -41,7 +50,8 @@ def draw(data: Data):
41
  pipe = StableDiffusionPipeline.from_pretrained(model_id, revision='fp16', torch_dtype=torch.float16)
42
  pipe = pipe.to('cuda')
43
 
44
- image = pipe(prompt, negative_prompt=n_prompt).images[0]
 
45
 
46
  fileName = "sd_" + str(time.time()) + '.png'
47
  image.save("/code/tmpdir/" + fileName)
 
1
  import os
2
  import time
3
  import sys
4
+ import re
5
+ import random
6
  import torch
7
  from fastapi import FastAPI
8
  from fastapi.staticfiles import StaticFiles
 
29
  if data.member_secret != "" and data.member_secret == os.environ.get("MEMBER_SECRET"):
30
  print(f"Is CUDA available: {torch.cuda.is_available()}")
31
 
32
+ text = re.sub('^#', '', data.string)
33
+
34
+ if '_seed' in text:
35
+ seed = 1024
36
+ else:
37
+ seed = random.randrange(1024)
38
+
39
+ # prompt = '(('+text+')) (( photograph )), highly detailed, sharp focus, 8k, 4k, (( photorealism )), detailed, saturated, portrait, 50mm, F/2.8, 1m away, ( global illumination, studio light, volumetric light ), ((( multicolor lights )))'
40
+ prompt = '(('+text+')) (( photograph )), highly detailed, sharp focus, 8k, 4k, (( photorealism )), detailed, saturated, portrait, 50mm, F/2.8, 1m away, ((( multicolor lights )))'
41
  n_prompt = 'text, blurry, art, painting, rendering, drawing, sketch, (( ugly )), (( duplicate )), ( morbid ), (( mutilated )), ( mutated ), ( deformed ), ( disfigured ), ( extra limbs ), ( malformed limbs ), ( missing arms ), ( missing legs ), ( extra arms ), ( extra legs ), ( fused fingers ), ( too many fingers ), long neck, low quality, worst quality'
42
 
43
  # https://huggingface.co/docs/hub/spaces-sdks-docker-first-demo
 
50
  pipe = StableDiffusionPipeline.from_pretrained(model_id, revision='fp16', torch_dtype=torch.float16)
51
  pipe = pipe.to('cuda')
52
 
53
+ generator = torch.Generator("cuda").manual_seed(seed)
54
+ image = pipe(prompt, negative_prompt=n_prompt, guidance_scale=7.5, generator=generator).images[0]
55
 
56
  fileName = "sd_" + str(time.time()) + '.png'
57
  image.save("/code/tmpdir/" + fileName)