Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def sdf_request(prompt: str, photo: str) -> dict:
- prompt_data = prompt_gen(prompt, photo)
- lora = loras_types.get(prompt, {}).get('lora', '')
- url = url_stable
- url_type = prompt_settings.get(prompt, {}).get('url_type', 'text2img') # тип запроса подбирается в заввисимости от выбора
- start = time.time()
- if lora:
- prompt_data['embeddings_model'] = ''
- style = loras_types.get(prompt, {}).get('prompt', '')
- if style:
- prompt_data['prompt'] = style
- prompt_data['lora_model'] = lora
- prompt_data['lora'] = lora
- prompt_data['lora_strength'] = 0.8
- url = lora_url
- url_type = ''
- async with ClientSession() as session:
- print(url)
- response = await session.post(url+url_type,
- headers=headers_stable,
- data=json.dumps(prompt_data))
- body = await response.json()
- logger.debug(body)
- response.close()
- if body['status'] == 'processing':
- id_ = body['id']
- i = 30
- while body['status'] == 'processing' and i > 0:
- url = f'{fetch_url}{id_}'
- data = {'key': os.environ.get('STABILITY_KEY')}
- if lora:
- data['request_id'] = id_
- url = lora_url
- async with ClientSession() as session:
- response = await session.post(url,
- headers=headers_stable,
- data=json.dumps(data))
- logger.debug(body)
- body = await response.json()
- response.close()
- i -= 1
- await asyncio.sleep(2)
- if body['status'] == 'processing':
- return await sdf_request(prompt, photo)
- if body['status'] == 'failed' or body['status'] == 'error':
- return await sdf_request(prompt, photo)
- logger.debug(body)
- return {'photo_url': body['output'][0],
- 'prompt': prompt_data,
- 'generation_time': body.get('generationTime',
- time.time() - start)}
- def prompt_gen(prompt: str, photo: str) -> dict:
- prompt_data = deepcopy(base_prompt)
- model_id = prompt_settings.get(prompt, {}).get('model_id', 'anything-v5')
- prompt_data['model_id'] = model_id
- prompt_data['key'] = os.environ.get('STABILITY_KEY')
- prompt_data['prompt'] = prompt
- prompt_data['init_image'] = photo
- prompt_data['lora_model'] = ''
- prompt_data['lora'] = ''
- prompt_data['lora_strength'] = ''
- return prompt_data
- # ниже вариации промптов и настроек которые выбираются в зависимости от выбора пользоввателчя
- # --------------------------->
- base_prompt = {
- 'model_id': 'anything-v5',
- 'init_image': '',
- 'mask_image': None,
- 'control_image': None,
- 'width': '512',
- 'height': '512',
- 'prompt': '',
- "use_karras_sigmas": "yes",
- 'safety_checker': 'yes',
- 'auto_hint': 'yes',
- 'tomesd': None,
- 'vae': 'sd-ft-mse',
- 'embeddings': None,
- 'multi_lingual': None,
- 'upscale': None,
- 'negative_prompt': "bad-picture-chill-75v, bad-artist-anime,bad-artist, badhandv4,bad_prompt, bad_prompt_version2, EasyNegative, negative_hand-neg, ng_deepnegative_v1_75t, Unspeakable-Horrors-Composition-4v, verybadimagenegative_v1.3",
- 'samples': '1',
- 'safety_checker': 'yes',
- 'auto_hint': 'yes',
- 'steps': 20,
- 'webhook': None,
- 'track_id': None,
- 'scheduler': 'EulerAncestralDiscreteScheduler',
- 'base64': None,
- 'temp': None,
- "controlnet_model": "depth,canny",
- "controlnet_type": "depth,canny",
- "controlnet_conditioning_scale": 0.5,
- "embeddings_model": "bad-picture-chill-75v, bad-artist-anime,bad-artist, badhandv4, bad_prompt, bad_prompt_version2, EasyNegative, negative_hand-neg, ng_deepnegative_v1_75t, Unspeakable-Horrors-Composition-4v, verybadimagenegative_v1.3",
- 'lora': '',
- 'enhance_prompt': 'yes',
- 'num_inference_steps': 4,
- "guess_mode": "no",
- "guidance_scale": 7,
- "clip_skip": 3,
- "strength": 0.7,
- 'seed': None
- }
- loras_types = {
- 'ghibli style': {
- 'lora': 'ghibli-style'
- },
- 'naruto style, a ninja': {
- 'lora': 'naruto-oneai'
- },
- 'kimetsu no yaiba style': {
- 'lora': 'vampire-killer'
- },
- 'toriyama akira': {
- 'lora': 'akira-toriyama'
- },
- 'wanostyle': {
- 'lora': 'wanostyle'
- },
- 'black and white, gothic, cmics style': {
- 'lora': 'gothic-style'
- },
- 'vox machina style': {
- 'lora': 'american-comics'
- },
- 'jim lee': {
- 'lora': 'superhero-comic'
- },
- 'IrisCompiet': {
- 'lora': 'watercolore'
- },
- 'asim style': {
- 'lora': 'yellow-family',
- 'prompt': 'simpsons style'
- },
- }
- prompt_settings = {
- "(pirate),(jolly roger),(wooden ship),(sailing the high seas),(pirate flag),(treasure chest),(pirate hat),(eye patch),(parrot on shoulder),(sword),(pirate captain),(sailors),(cannon),(ship's wheel),(pirate ship silhouette),(pirate crew),(pirate's treasure),(sunken ship)": {
- 'model_id': 'realistic vision',
- 'url_type': 'img2img'
- },
- '(futuristic aesthetic),(cybernetic enhancements),(holographic elements),(neon lights),(vibrant colors),(cyberpunk style),(cybernetic implants)': {
- 'model_id': 'realistic vision',
- 'url_type': 'img2img'
- },
- "(Lord of the Realm),(Royal regalia),(Golden crown),(Ornate cape),(Jeweled scepter),(Regal attire),(Lord's castle),(Throne room),(Courtiers),(Loyal subjects),(Knight in armor),(Banner of the realm),(Great hall),(Tapestry),(Feast table),(Grand staircase),(Crest of the realm),(Enchanted forest),(Majestic mountains)": {
- 'model_id': 'realistic vision',
- 'url_type': 'img2img'
- },
- 'image of a one person in Avatar movie style': {
- 'model_id': 'realistic vision',
- 'url_type': 'img2img'
- },
- "(egyptian pharaoh),(pharaoh's headdress),(royal attire),(golden crown),(pharaoh's scepter),(beard),(royal collar),(kohl-lined eyes),(ornate jewelry),(royal staff),(pharaoh's mask),(pyramids),(temple),(papyrus scrolls),(anubis statue),(hieroglyphics),(obelisk),(sphinx)": {
- 'model_id': 'realistic vision',
- 'url_type': 'img2img'
- },
- '(western),(dusty environment),(sunset),(cowboy hat),(saloon),(horse),(lone cowboy)': {
- 'model_id': 'realistic vision',
- 'url_type': 'img2img'
- },
- "Oil painting,landscape,impressionistic style,(vibrant brushstrokes:1.2),(capturing light and shadow),(textured canvas),(rich color palette),(expressive application of paint),(blending of colors),(lush scenery),(natural beauty),(serene atmosphere),(subtle nuances),(captivating composition),(dynamic brushwork),(dramatic skies),(play of light),(harmonious color harmony),(capturing atmosphere),(realistic details),(sublime beauty),(timeless charm),(impression of depth),(pleasing color transitions),(evoke emotion),(captivating textures),(organic shapes),(capturing nature's essence),(mood and atmosphere),(expressive landscapes),(dynamic and energetic),(intimate scenes),(peaceful tranquility),(painterly style),(layering and glazing),(nuanced tonal values),(capturing the fleeting moment),(evocative storytelling),(implied movement),(masterful use of color),(sweeping brushstrokes),(textured foliage),(capturing reflections),(subtle variations in light and shadow),(interpretive quality),(painter's vision),(layered depth),(impressionistic interpretation)": {
- 'model_id': 'anything-v5',
- 'url_type': 'img2img'
- },
- 'IrisCompiet': {
- 'model_id': 'anything-v5',
- 'url_type': 'img2img'
- },
- "ukiyo-e,landscape,cherry blossoms,traditional bridge,serene,(vibrant colors:1.2),(delicate brushwork:1.5),(floating petals),(tranquil atmosphere:1.3),(graceful curves),(gentle flowing river),bridge spanning river,overarching branches,(subtle sunlight:1.2),(dappled shadows),(lush foliage),(elegant composition:1.3),(ethereal beauty),(cherry blossom petals in the wind),(traditional architecture),(reflective water),(sense of harmony),(ukiyo-e stylization),(classic woodblock printing),(timeless charm),(cherry blossom festival),(celebration of nature),(seasonal transition),(transient beauty:1.4),(embrace of impermanence),(fine details),(carefully rendered landscape),(symbol of renewal),(sublime moment),(serenity amidst nature),(sublime beauty:1.2),(blossoming sakura tree),(picturesque scenery),(soft pastel colors),(celestial backdrop),(contemplative scene),(time-honored tradition)": {
- 'model_id': 'anything-v5',
- 'url_type': 'img2img'
- }
- }
Add Comment
Please, Sign In to add comment