├── config ├── aisettings.txt ├── igsettings.txt └── captions.txt ├── run.bat ├── output ├── 1.jpg ├── 2.jpg ├── 3.jpg └── 4.jpg ├── requirements.txt ├── setup.bat ├── models └── instructions.txt ├── igbot.py ├── setup.py ├── README.md └── main.py /config/aisettings.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 100 3 | 0 4 | 0 -------------------------------------------------------------------------------- /run.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | python -u "main.py" 3 | pause 4 | -------------------------------------------------------------------------------- /config/igsettings.txt: -------------------------------------------------------------------------------- 1 | USERNAME 2 | PASSWORD 3 | #like4like #follow4follow 4 | 0 -------------------------------------------------------------------------------- /output/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louistaii/AI-Influencer/HEAD/output/1.jpg -------------------------------------------------------------------------------- /output/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louistaii/AI-Influencer/HEAD/output/2.jpg -------------------------------------------------------------------------------- /output/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louistaii/AI-Influencer/HEAD/output/3.jpg -------------------------------------------------------------------------------- /output/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louistaii/AI-Influencer/HEAD/output/4.jpg -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | diffusers==0.25.0 2 | gdown==4.7.1 3 | instagrapi==2.0.1 4 | Pillow==10.1.0 5 | psutil==5.9.7 6 | torch==2.0.1+cu118 7 | -------------------------------------------------------------------------------- /setup.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | echo Installing Dependencies... 3 | pip install -r requirements.txt 4 | pause 5 | cls 6 | python -u "setup.py" 7 | pause 8 | cls 9 | python -u "main.py" 10 | 11 | -------------------------------------------------------------------------------- /models/instructions.txt: -------------------------------------------------------------------------------- 1 | To use your own custom model, rename your model file to realistic (for models with SD v1-5 base) or realisticXL (SDXL v1.0 based) and then place the model folder into this folder. 2 | Custom LORA weights can be used by replacing the weight.safetensors (for models with SD v1-5 base) or weightsXL((SDXL v1.0 based)) file in this folder with your trained weight. -------------------------------------------------------------------------------- /igbot.py: -------------------------------------------------------------------------------- 1 | import pathlib 2 | import random 3 | import os 4 | from instagrapi import Client 5 | from instagrapi.types import Location 6 | 7 | 8 | 9 | 10 | path = pathlib.Path(__file__).parent.resolve() 11 | cl = Client() 12 | 13 | def f4f(): 14 | posts = cl.hashtag_medias_recent("like4like", 5) 15 | for i in range(5): 16 | print(f"Liked Post {i+1}") 17 | cl.media_like(posts[i].id) 18 | cl.user_follow(posts[i].user.pk) 19 | print("Followed " + posts[i].user.username) 20 | 21 | 22 | 23 | 24 | def getcaption(hashtags): 25 | num = random.randint(0,99) 26 | f = open(f"{path}/config/captions.txt", encoding="utf8") 27 | content = f.readlines() 28 | caption = content[num] + hashtags 29 | f.close() 30 | return caption 31 | 32 | 33 | def postimg(imgpath, caption): 34 | print("Posting with caption: " + caption) 35 | cl.photo_upload( 36 | imgpath, 37 | caption, 38 | location=Location(name='Singapore', lat=1.351880, lng =103.823339) 39 | ) 40 | 41 | def storyimg(imgpath, caption): 42 | print("Uploading Story") 43 | cl.photo_upload_to_story(imgpath, caption) 44 | 45 | 46 | def auto(hashtags, algo, confirm): 47 | prev = 1 48 | while (os.path.exists(f"{path}/output/{prev}.jpg")): 49 | prev+=1 50 | latest = prev - 1 51 | imgpath = f"{path}/output/{latest}.jpg" 52 | caption = getcaption(hashtags) 53 | 54 | #gain confirmation 55 | if int(confirm) == 0: 56 | print(f"Upload {latest}.jpg with caption: {caption} ? ") 57 | confirmation = input("[y/n]:") 58 | if (confirmation == "y" or confirmation == "Y"): 59 | postimg(imgpath, caption) 60 | if int(algo) == 0: 61 | f4f() 62 | else: 63 | quit() 64 | else: 65 | postimg(imgpath, caption) 66 | if int(algo) == 0: 67 | f4f() 68 | 69 | 70 | 71 | 72 | def main(): 73 | f = open(f"{path}/config/igsettings.txt", "r") 74 | username, password, hashtags, algo, confirm = f.read().splitlines() 75 | f.close() 76 | 77 | print(f"Logging in to @{username}") 78 | cl.login(username, password) 79 | auto(hashtags, algo, confirm) 80 | 81 | 82 | if __name__ == "__main__": 83 | main() 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /config/captions.txt: -------------------------------------------------------------------------------- 1 | Embracing the chaos and finding beauty within. 🌪️✨ 2 | Lost in wanderlust, found in adventure. 🗺️✈️ 3 | Always take the scenic route. 🛤️🌄 4 | Serenity in simplicity. 🌿💫 5 | Creating my own sunshine on cloudy days. ☀️☁️ 6 | Dream big, sparkle more. ✨✨ 7 | Just another daydreamer with wanderlust. 🌌🌍 8 | Coffee in one hand, confidence in the other. ☕💃 9 | Dancing through life, one step at a time. 💫👣 10 | In a romance with the universe. 💖🌌 11 | Life's a canvas, make it colorful! 🎨🌈 12 | Finding joy in the journey, not just the destination. 🚗🌟 13 | Living life with a smile as my compass. 😊🌸 14 | Never fully dressed without a smile. 😄👗 15 | Sunshine mixed with a little hurricane. 🌪️☀️ 16 | Wander often, wonder always. 🌍✨ 17 | Making memories around the world. 🌏📸 18 | Being both soft and strong is a superpower. 💪🌸 19 | Chasing sunsets and dreams. 🌅💭 20 | Spreading kindness like confetti. 🎉💖 21 | Collecting moments, not things. 📸🌟 22 | Living my story, one adventure at a time. 📖✨ 23 | Radiating good vibes and positivity. 🌟☮️ 24 | Embracing my perfectly imperfect self. 🌺🌟 25 | Adventure awaits where the WiFi is weak. 🌐🌿 26 | Laughing at life's beautiful chaos. 😄🌼 27 | Sippin' on sunshine and good vibes. ☀️✌️ 28 | Life is short, make it sweet. 🍭💫 29 | Lost in the right direction. 🌟🌿 30 | Born to stand out in a world full of copycats. 🌟🦄 31 | Sparkle like you mean it. ✨💖 32 | Finding magic in the mundane. ✨🌟 33 | Living for the moments that take your breath away. 🌈🌬️ 34 | Adventure is calling, gotta go! 📞🌍 35 | Celebrating the art of being me. 🎨🌟 36 | Making every moment count. ⏳💫 37 | Dancing through life's ups and downs. 💃🎢 38 | Radiating positivity like it's going out of style. ✌️☀️ 39 | Being extra with a side of fabulous. 💁🌟 40 | Life's too short to not eat dessert first. 🍰🍭 41 | Dreaming in colors borrowed from the sea. 🌊🎨 42 | Living life with no regrets, just lessons learned. 📚🌟 43 | Finding joy in the ordinary. 🌼💫 44 | Fearless and fabulous. 💃🌟 45 | Living my best life one adventure at a time. 🌟🌍 46 | Embracing my wild and free spirit. 🌿🦋 47 | Choosing happiness every single day. 😊💫 48 | Spreading love, light, and good vibes. 💖☀️ 49 | Adventure begins where plans end. 🗺️🌟 50 | Glitter runs through my veins. ✨💖 51 | Finding my own kind of beautiful. 🌸✨ 52 | Making memories that will last a lifetime. 📸🌟 53 | Exploring the world one adventure at a time. 🗺️✈️ 54 | Chasing sunsets and dreams. 🌅💫 55 | Life's a journey, not a race. 🏃‍♀️🌟 56 | Dreaming big, living bigger. 💭🌟 57 | Sprinkling kindness like confetti. 🎉💖 58 | Embracing the messiness of life. 🌪️🌸 59 | Living on caffeine and wanderlust. ☕✈️ 60 | Spreading positivity like wildfire. 🔥✨ 61 | Happiness looks gorgeous on me. 😊🌟 62 | Finding joy in the little things. 🌼💫 63 | Adventure is out there, and I'm chasing it! 🌟🌍 64 | Making moments matter. 🌟📸 65 | Life's too short to wear boring clothes. 👗🌟 66 | Collecting sunsets and memories. 🌅📸 67 | Embracing my perfectly imperfect self. 💖🌟 68 | Sparkling my way through life. ✨💫 69 | Adventure is my soul's best friend. 🌟🧭 70 | Living my story, one chapter at a time. 📖✨ 71 | All about that positive vibe tribe. ✌️🌟 72 | Life's a party, dress like it! 🎉👗 73 | Dreaming of endless adventures. 💭🌟 74 | Chasing dreams and sunbeams. ☀️💫 75 | Striving for progress, not perfection. 🌟📈 76 | Making waves and riding high. 🌊🏄‍♀️ 77 | Radiating good vibes only. ✨☮️ 78 | Capturing moments and creating memories. 📸🌟 79 | Born to stand out in a world of followers. 🌟🌍 80 | Living my best life, one smile at a time. 😄🌟 81 | Wild heart, free spirit. 🌿🌟 82 | Spreading sunshine wherever I go. ☀️🌟 83 | Adventure is calling, gotta answer! 📞🌟 84 | Embracing the beauty of imperfection. 🌺✨ 85 | Life's a journey, enjoy the ride! 🚗🌟 86 | Living on sunshine and good vibes. ☀️💫 87 | Making memories in every moment. 🌟📸 88 | Loving fiercely and living fearlessly. 💖🌟 89 | Dancing through life's adventures. 💃🌟 90 | Living each day like it's my favorite. 🌟📆 91 | Finding joy in the everyday chaos. 🌪️🌟 92 | Spreading love, light, and laughter. 💖✨ 93 | Embracing my inner spark. 🌟🔥 94 | Adventure is out there, and I'm ready! 🌟🌍 95 | Making life a beautiful adventure. 🌟🌸 96 | Dreaming big and making it happen. 💭🌟 97 | In love with the magic of simple moments. ✨🌟 98 | Creating a life I love, one day at a time. 🌟💖 99 | Living life, one adventure after another. 🌟🌍 100 | Finding magic in every moment. ✨🌟 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import pathlib 2 | import psutil 3 | import torch 4 | 5 | class bcolors: 6 | HEADER = '\033[95m' 7 | ENDC = '\033[0m' 8 | BOLD = '\033[1m' 9 | 10 | 11 | path = pathlib.Path(__file__).parent.resolve() 12 | 13 | def igsaveconfig(username, password, hashtag, algo, confirm): 14 | f = open(f"{path}/config/igsettings.txt", "w") 15 | f.writelines(f"{username}\n{password}\n{hashtag}\n{algo}\n{confirm}") 16 | f.close() 17 | igconfig() 18 | 19 | def iginfo(hashtag, algo, confirm): 20 | username = input("Instagram username (without the @): ") 21 | password = input("Password: ") 22 | igsaveconfig(username,password,hashtag,algo,confirm) 23 | igconfig() 24 | 25 | def ighashtag(username,password,confirm): 26 | print("\nInput wanted hashtags in captions (eg.'#like4like #follow4follwow'). Leave blank if no hashtags are needed") 27 | hashtag = input("hashtags: ") 28 | yesno = input("Enable increase followers algorithm? [Y/N]: ") 29 | if yesno.lower == 'y': 30 | algo = 0 31 | else: 32 | algo = 1 33 | 34 | igsaveconfig(username,password,hashtag,algo,confirm) 35 | igconfig() 36 | 37 | def igconfirm(username, password,hashtag,algo): 38 | 39 | choice = input("Require confirmation before posting? [Y/N]:") 40 | if choice.lower() == 'y': 41 | confirm = 0 42 | else: 43 | confirm =1 44 | 45 | igsaveconfig(username,password,hashtag,algo,confirm) 46 | igconfig() 47 | 48 | 49 | def igconfig(): 50 | 51 | f = open(f"{path}/config/igsettings.txt", "r") 52 | username, password, hashtag, algo, confirm = f.read().splitlines() 53 | f.close() 54 | 55 | print(f"{bcolors.BOLD}\nMenu{bcolors.ENDC} \n1.) Input / change login info \n2.) Hashtags settings \n3.) Confirmation before posting \n4.) Quit") 56 | 57 | choice = input("Enter 1, 2, 3 or 4: ") 58 | if choice == "1": 59 | iginfo(hashtag,algo,confirm) 60 | if choice == "2": 61 | ighashtag(username, password,confirm) 62 | if choice == "3": 63 | igconfirm(username, password,hashtag,algo) 64 | if choice == "4": 65 | quit() 66 | 67 | 68 | def recommended(): 69 | ram = (round(psutil.virtual_memory().total / (1024.0 **3))) 70 | 71 | if torch.cuda.is_available(): 72 | # Get the total GPU memory 73 | total_memory = torch.cuda.get_device_properties(0).total_memory 74 | vrammb = total_memory / (1024 ** 2) 75 | vram = round(vrammb/(1000)) 76 | else: 77 | vram = 0 78 | 79 | print(f"You have {ram} GB of ram and {vram} GB of VRAM") 80 | 81 | if ram<=4 and vram <=2: 82 | print(f"{bcolors.BOLD}Low Tier PC config recommended{bcolors.ENDC}") 83 | elif ram >6 and vram >=10: 84 | print(f"{bcolors.BOLD}High Tier PC config recommended{bcolors.ENDC}") 85 | else: 86 | print (f"{bcolors.BOLD}Mid Tier PC config recommended{bcolors.ENDC}") 87 | 88 | 89 | def saveconfig(model,steps): 90 | # for auto prompt 91 | autoprompt = input("Enable auto prompt generation? [Y/N]:") 92 | if (autoprompt.lower() == 'y'): 93 | autoprompt = 0 94 | else: 95 | autoprompt = 1 96 | 97 | 98 | enablebotchoice = input("Link Instagram bot to image generator? [Y/N]:") 99 | if (enablebotchoice.lower() == 'y'): 100 | enablebot = 0 101 | else: 102 | enablebot = 1 103 | 104 | 105 | f = open(f"{path}/config/aisettings.txt", "w") 106 | f.writelines(f"{model} \n{steps} \n{autoprompt} \n{enablebot}") 107 | f.close() 108 | print(f"{bcolors.HEADER}Settings saved.{bcolors.ENDC}") 109 | 110 | if enablebot == 0: 111 | print(f"{bcolors.HEADER}Instagram Bot Config.{bcolors.ENDC}") 112 | igconfig() 113 | 114 | quit() 115 | 116 | 117 | def aiconfig(): 118 | print("Select configuration \n1.) Low Tier PC config \n2.) Mid Tier PC config \n3.) High Tier PC config \n4.) Custom") 119 | config = input("Enter 1, 2, 3 or 4: ") 120 | 121 | if config == "1": 122 | saveconfig(1,30) 123 | if config == "2": 124 | saveconfig(2,60) 125 | if config == "3": 126 | saveconfig(2,100) 127 | 128 | print(f"{bcolors.HEADER}\nCustom Config Setup{bcolors.ENDC}") 129 | 130 | print("Choose Stable Diffusion model: \n1.) SD v1-5 (Realistic Vision v6) \n2.) SDXL v 1.0 (SDXL Yamer's Realistic)") 131 | model = input("Enter 1 or 2: ") 132 | print(f"More inference steps leads to higher RAM/VRAM usage but better generated image quality. {bcolors.BOLD}We recommend any in the range of 30 to 100{bcolors.ENDC}") 133 | steps = input("Input number of inference steps: ") 134 | saveconfig(model, steps) 135 | 136 | 137 | def main(): 138 | print(f"{bcolors.HEADER}AI INFLUENCER SETUP{bcolors.ENDC}") 139 | print("") 140 | recommended() 141 | aiconfig() 142 | 143 | 144 | 145 | 146 | if __name__ == "__main__": 147 | main() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # AI Influencer 3 | The purpose of this project is to create an AI Instagram influencer by automating both the generation of AI Instagram worthy images and the management of an Instagram account. See [Claire Reety](#claire) for example of implementation. The repository consists of 2 parts: [AI image generation](#generating-ai-images) and [Instagram bot](#instagram-bot). AI Influencer also comes with a low spec mode to enable lower tier PCs to run the project. However, this comes with the cost of lower quality images. 4 | Note: AI image generation can work independently from the Instagram handler bot if the user chooses not to upload to Instagram. 5 | 6 | ## Generating AI images 7 | ### Introduction 8 | This part of the project is mainly powered by Diffusers from [huggingface](https://huggingface.co/docs/diffusers/index). To generate consistent facial features, this project utilizes trained image generating models and LORA weights. It's primarily optimized for generating Claire's distinctive features. However, it's adaptable for those with their own trained models to use. All generated images are saved in the "outputs" folder. 9 | Note: Intial run will take significantly longer due to the initial download of stable diffusion. Expect subsequent run times to be faster. 10 | 11 |
12 | 13 |
14 | 15 | ### Features 16 | - Option to use different models / trained LORA weight 17 | - Auto prompt generator to increase automation and vary the images generated for more realism 18 | - Enhanced NSFW checker to detect and replace NSFW generated images generated 19 | - Highly customizable configuration. Includes low spec mode for lower CPU/GPU usage and high spec mode for better quality results. 20 | 21 | ### Models 22 | - The image models used are pre trained models based off [stable-diffusion-xl-base-1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) and [stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5). They can be found here: [Realistic Vision V6.0 B1](https://civitai.com/models/4201/realistic-vision-v60-b1) (SD v1-5 base) , [SDXL Yamer's Realistic](https://civitai.com/models/127923?modelVersionId=272724) (SDXL v1.0 base). These models are trained to generate images with greater realism which enhances the objective of this project. 23 | - To use your own custom model, rename your model file to ```realistic``` (for models with SD v1-5 base) or ```realisticXL``` (SDXL v1.0 based) and then place the model folder into the folder named "models". 24 | Custom LORA weights can be used by replacing the ```weight.safetensors``` (for models with SD v1-5 base) or ```weightXL.safetensors``` (SDXL v1.0 based) file in the "models" folder with your trained weights. 25 | 26 | 27 | 28 | ## Instagram Bot 29 | Simple Instagram bot that automates the selection of images and captions for a Instagram post and posts it. 30 | Comes with a hashtag feature to add custom hashtags in captions and an [algorithm](#algorithm) to increase social media traction. 31 | Captions are chosen by random from a list of 100 intriguing captions. The list of captions can be edited by editing the ```captions.txt``` file in the "config" folder. 32 | Note: the bot only works for existing Instagram accounts and will not create one for you. 33 | ### Algorithm 34 | Immediately after posting an image, AI Influencer will browse recent posts under the #like4like category, engaging by liking them and following their respective accounts. This helps publicise the account to other users and aims to boost the like and following counts on the account. 35 | 36 | 37 | ## Updates 38 | - **`2023-30-12`**: Automatic prompt generator added to vary type of images generated for better realism. "setup.py" and "requirements.txt" updated. Tests for NSFW images implemented and automatic re-generating of images until SFW ones produced. 39 | - **`2024-01-01`**: Happy New Year! Improved setup and implementation of instagram bot. 40 | - **`2024-03-01`**: Fixed setup bugs and simplified code. Improved SD v1-5 trained LORA weights. Auto downloading of LORA weight files. 41 | 42 | ## Quick Start 43 | 44 | ### Installation 45 | Clone this repository and run 'setup.bat' to install the [dependencies](#dependencies) needed. 46 | Alternatively, you could run ```pip install -r requirements.txt``` in the directory and then run "setup.py". 47 | Simply launch 'run.bat' after configuration to start the project and the intial download of Stable Diffusion. 48 | 49 | 50 | 51 | 52 | ## Dependencies 53 | - Compatibillity for Python 3.10.8 - 3.11 54 | - Minimum 4GB of VRAM (12GB reccomended) and 12GB of space 55 | - diffusers v0.25.0 56 | - gdown v4.7.1 57 | - instagrapi v2.0.1 58 | - Pillow v10.1.0 59 | - psutil v5.9.7 60 | - torch v2.0.1+cu118 61 | 62 | 63 | 64 | ## Claire 65 |
66 |

67 | Give Claire Reety a follow on Instagram! Click on the image below! 68 |

69 |

70 | 71 |

72 |
73 | 74 | Claire's features are entirely AI-generated, derived from multiple rounds of image prompting using Stable Diffusion. Images with her features were then used to train and create the LORA weight found in the repository. 75 | 76 |
77 | 78 |
79 | 80 | Claire's Instagram account operates on this project by configuring it for complete automation and server compatibility (lower CPU/GPU usage). The repository is being hosted on a [Pytonanywhere](https://www.pythonanywhere.com/) server as they have no hard limits on CPU usage. The project automatically runs once a day on randomly generated timings to evade Instagram's bot detection. 81 | 82 | 83 | 84 | ## Other examples 85 | - Generated with pre trained SD v1-5 and external [LORA weight](https://civitai.com/models/171781?modelVersionId=192959) 86 |
87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pathlib 3 | import random 4 | import igbot 5 | 6 | from diffusers import StableDiffusionXLPipeline 7 | from diffusers import StableDiffusionPipeline 8 | import torch 9 | import gdown 10 | from PIL import Image 11 | 12 | #declare project directory 13 | path = pathlib.Path(__file__).parent.resolve() 14 | 15 | #reads in settings and load the config 16 | def aiconfig(): 17 | settings = [0,0,0,0] 18 | f = open(f"{path}/config/aisettings.txt", "r") 19 | j = 0 20 | for x in f: 21 | settings[j] = int(x) 22 | j += 1 23 | f.close() 24 | return settings 25 | 26 | 27 | 28 | def testNSFW(img): 29 | #get colours in image 30 | colors = img.getcolors(1000) 31 | max_occurence, most_present = 0, 0 32 | try: 33 | for c in colors: 34 | if c[0] > max_occurence: 35 | (max_occurence, most_present) = c 36 | return most_present #returns most detected colour 37 | except TypeError: 38 | return 39 | 40 | 41 | 42 | # automatically generates random prompts each time 43 | def getprompt(): 44 | where = "" 45 | when = "" 46 | expression = "" 47 | pictype = "" 48 | 49 | locationnum = random.randint(0,4) 50 | if (locationnum == 0): 51 | where = " outdoors" 52 | elif (locationnum == 1): 53 | where = " indoors" 54 | elif (locationnum == 2): 55 | where = " in nature" 56 | elif (locationnum == 3): 57 | where = " in a city" 58 | 59 | timenum = random.randint(0,2) 60 | if (timenum == 0): 61 | when = " at night" 62 | 63 | expressionnum = random.randint(0,99) 64 | if (expressionnum in range (0,39,1)): # 40% chance due to better results 65 | expression = " smiling" 66 | elif (expressionnum in range (40,49,1)): # 10% chance 67 | expression = " sad" 68 | elif (expressionnum in range (50,59,1)): #last 40% dedicated to no expression 69 | expression = " angry" 70 | 71 | picnum = random.randint(0,9) 72 | if (picnum == 0): 73 | pictype = "close up picture of " 74 | where,when = "" , "" 75 | elif (picnum == 1): 76 | pictype = "selfie of " 77 | 78 | 79 | prompt = f"{pictype}woman{where}{when}{expression}" 80 | print(prompt) 81 | return prompt 82 | 83 | 84 | 85 | def getimage(pipe, prompt,steps): 86 | 87 | #generate image 88 | negprompt = "deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, NSFW" 89 | output = pipe(prompt=prompt, 90 | num_inference_steps=steps, 91 | height=1024, width=1024, 92 | negative_prompt = negprompt).images[0] 93 | 94 | #saving image into output folder 95 | name = 1 96 | while (os.path.exists(f"{path}/output/{name}.jpg")): 97 | name+=1 98 | 99 | output.save(f"{path}/output/{name}.jpg") 100 | 101 | 102 | 103 | def main(): 104 | 105 | settings = aiconfig() 106 | 107 | #choose models based off settings 108 | if settings[0] == 1: #using SD v1-5 109 | modelpl = StableDiffusionPipeline 110 | if os.path.exists(f"{path}/models/realistic"): 111 | model = f"{path}/models/realistic" 112 | else: 113 | model = "SG161222/Realistic_Vision_V6.0_B1_noVAE" 114 | 115 | if os.path.exists(f"{path}/models/weight.safetensors") == False: #downloads claire LORA weights 116 | print("Downloading Claire trained weights for SD v1-5...") 117 | url = "https://drive.google.com/uc?id=1_X5vV409D0mr8fU2N7i5vu1rnToV8jBD" 118 | output = f"{path}/models/weight.safetensors" 119 | gdown.download(url, output, quiet=False) 120 | 121 | else: #using SDXL 1.0 122 | modelpl= StableDiffusionXLPipeline 123 | 124 | if os.path.exists(f"{path}/models/realisticXL") == False: 125 | print("Downloading trained model for SDXL 1.0...This make take awhile...") 126 | url = "https://drive.google.com/drive/folders/1xTRiqZ__XhLR0zxbTaMTG21yYK3-z30u?usp=sharing" 127 | output = f"{path}/models/realisticXL" 128 | gdown.download_folder(url, output = output,quiet=True, use_cookies=False) 129 | 130 | model = f"{path}/models/realisticXL" 131 | 132 | 133 | if os.path.exists(f"{path}/models/weightXL.safetensors") == False: #downloads claire LORA weights 134 | print("Downloading Claire trained weights for SDXL 1.0...") 135 | url = "https://drive.google.com/uc?id=1EJsV_2zqseAypcH_v_Eku49x7QMtJMeE" 136 | output = f"{path}/models/weightXL.safetensors" 137 | gdown.download(url, output, quiet=False) 138 | 139 | 140 | #check for cuda support and setup pipeline accordingly 141 | if torch.cuda.is_available() == True: 142 | pipe = modelpl.from_pretrained(model, 143 | torch_dtype=torch.float16 144 | ) 145 | pipe = pipe.to("cuda") 146 | else: 147 | print('Pytorch with Cuda support not found, proceeding with CPU only...') 148 | pipe = modelpl.from_pretrained(model, 149 | torch_dtype=torch.float32 150 | ) 151 | 152 | 153 | steps = round(int(settings[1])) 154 | 155 | if settings[2] == 0: 156 | prompt = getprompt() 157 | else: 158 | prompt = input("Prompt: ") 159 | 160 | if(settings[0]==1): 161 | pipe.load_lora_weights(f"{path}/models/weight.safetensors") 162 | else: 163 | pipe.load_lora_weights(f"{path}/models/weightXL.safetensors") 164 | 165 | getimage(pipe, prompt, steps) 166 | 167 | 168 | #load latest generated image 169 | prev = 1 170 | while (os.path.exists(f"{path}/output/{prev}.jpg")): 171 | prev+=1 172 | latest = prev - 1 173 | img = Image.open(f"{path}/output/{latest}.jpg") 174 | 175 | 176 | #Regenerate image until a safe image is produced 177 | while testNSFW(img) == (0,0,0): 178 | print("Retrying. Consider changing prompts.") 179 | os.remove(f"{path}/output/{latest}.jpg") 180 | getimage(pipe, prompt, steps) 181 | 182 | #open final image 183 | img.show() 184 | 185 | if settings[3] == 0: 186 | igbot.main() 187 | 188 | 189 | 190 | 191 | 192 | if __name__ == "__main__": 193 | main() --------------------------------------------------------------------------------