-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.py
68 lines (51 loc) · 1.95 KB
/
image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import replicate
import requests
import os
def get_incremented_filename(base_filename, extension):
i = 1
while os.path.exists(f"{base_filename}-{i}{extension}"):
i += 1
new_filename = f"{base_filename}-{i}{extension}"
return new_filename
def create_image(prompt,filename):
def get_incremented_filename(base_filename, extension):
i = 1
while os.path.exists(f"{base_filename}-{i}{extension}"):
i += 1
new_filename = f"{base_filename}-{i}{extension}"
return new_filename
model = replicate.models.get("stability-ai/stable-diffusion")
version = model.versions.get("db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf")
# https://replicate.com/stability-ai/stable-diffusion/versions/db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf#input
inputs = {
# Input prompt
'prompt': prompt,
# pixel dimensions of output image
'image_dimensions': "768x768",
# Specify things to not see in the output
# 'negative_prompt': ...,
# Number of images to output.
# Range: 1 to 4
'num_outputs': 1,
# Number of denoising steps
# Range: 1 to 500
'num_inference_steps': 50,
# Scale for classifier-free guidance
# Range: 1 to 20
'guidance_scale': 7.5,
# Choose a scheduler.
'scheduler': "DPMSolverMultistep",
# Random seed. Leave blank to randomize the seed
# 'seed': ...,
}
output= version.predict(**inputs)
separator=''
output=separator.join(output)
print(output)
response = requests.get(output)
#filename=get_incremented_filename('image','.png')
filename='image.png'
with open(filename, 'wb') as f:
f.write(response.content)
return filename
# https://replicate.com/stability-ai/stable-diffusion/versions/db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf#output-schema