-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathasticaDesign_sample.py
More file actions
67 lines (56 loc) · 2.5 KB
/
Copy pathasticaDesign_sample.py
File metadata and controls
67 lines (56 loc) · 2.5 KB
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
67
import requests
import json
# API configurations
asticaAPI_key = 'YOUR API KEY' # visit https://astica.ai
asticaAPI_timeout = 60 # in seconds.
#See Input Documentation: https://astica.ai/design/documentation/#inputs
asticaAPI_endpoint = 'https://design.astica.ai/generate_image'
asticaAPI_modelVersion = '2.0_full'
asticaAPI_prompt = 'close-up photography of older gentleman standing in the rain at night, in a street lit by lamps'
asticaAPI_prompt_negative = ''
asticaAPI_generate_quality = 'faster' #high, standard, fast, faster
asticaAPI_generate_lossless = 0 #0 = Default JPG, 1 = lossless uncompressed PNG
asticaAPI_seed = 0 #0 will randomize the seed for every generation
asticaAPI_moderate = 1
asticaAPI_low_priority = 0 #0 = realtime, 1 = low_priority (lower cost)
# Prepare payload
asticaAPI_payload = {
'tkn': asticaAPI_key,
'modelVersion': asticaAPI_modelVersion,
'prompt': asticaAPI_prompt,
'prompt_negative': asticaAPI_prompt_negative,
'generate_quality': asticaAPI_generate_quality,
'generate_lossless': asticaAPI_generate_lossless,
'seed': asticaAPI_seed,
'moderate': asticaAPI_moderate,
'low_priority': asticaAPI_low_priority,
}
def asticaAPI(endpoint, payload, timeout):
response = requests.post(endpoint, data=json.dumps(payload), timeout=timeout, headers={ 'Content-Type': 'application/json', })
if response.status_code == 200:
return response.json()
else:
return {'status': 'error', 'error': 'Failed to connect to the API.'}
# call API function and store result
asticaAPI_result = asticaAPI(asticaAPI_endpoint, asticaAPI_payload, asticaAPI_timeout)
# print API output
# Handle asticaAPI response
if 'status' in asticaAPI_result:
# Output Error if exists
if asticaAPI_result['status'] == 'error':
print('Error:', asticaAPI_result['error'])
# Output Success if exists
elif asticaAPI_result['status'] == 'success':
if 'resultURI' in asticaAPI_result:
print('===============')
print('Low Priority URI: ', asticaAPI_result['resultURI'], '\nQuery this URL to obtain the output of your results')
print('===============')
else:
print('===============')
print('Generated Image:', asticaAPI_result['output'])
print('===============')
print('\nastica API Output:')
print(json.dumps(asticaAPI_result, indent=4))
print('=================')
else:
print('Invalid response')