Spaces:
Runtime error
Runtime error
| import datetime | |
| import webuiapi | |
| class SDApi: | |
| def __init__(self): | |
| # self.api = webuiapi.WebUIApi(host='127.0.0.1', port=7860) | |
| # self.api = webuiapi.WebUIApi(host='stable-diffusion-api.fc-stable-diffusion-plus.1021266052978015.cn-shanghai.fc.devsapp.net', port=80) | |
| self.api = webuiapi.WebUIApi(host="region-8.seetacloud.com", port=40794) | |
| webuiapi.ControlNetUnit = webuiapi.ControlNetUnit | |
| pass | |
| def get_now_model(self): | |
| return self.api.util_get_current_model() | |
| def set_now_model(self, model_name): | |
| options = {} | |
| options['sd_model_checkpoint'] = model_name | |
| return self.api.set_options(options) | |
| def get_all_models(self): | |
| return self.api.get_sd_models() | |
| def txt2img(self,prompt): | |
| try: | |
| result = self.api.txt2img( | |
| prompt=prompt, | |
| # negative_prompt="NSFW, illustration, 3d, sepia, painting, cartoons, sketch, (worst quality:2), (low quality:2), (normal quality:2), lowres, bad anatomy, bad hands, normal quality, ((monochrome)), ((grayscale:1.2)), futanari, full-package_futanari, penis_from_girl, newhalf, collapsed eyeshadow, multiple eyebrows, vaginas in breasts,holes on breasts, fleckles, stretched nipples, gigantic penis, nipples on buttocks, analog, analogphoto, signatre, logo,2 faces", | |
| # negative_prompt="(worst quality, low quality:1.4), ((text, signature, captions))", | |
| negative_prompt="", | |
| batch_size=4, | |
| seed=-1, | |
| styles=[], | |
| cfg_scale=7, | |
| sampler_index='Euler a', | |
| restore_faces=False, | |
| # restore_faces=True, | |
| width=762, | |
| height=512, | |
| steps=20, | |
| enable_hr=False, | |
| hr_scale=2, | |
| hr_upscaler=webuiapi.HiResUpscaler.Latent, | |
| hr_second_pass_steps=20, | |
| hr_resize_x=1536, | |
| hr_resize_y=1024, | |
| denoising_strength=0.4,) | |
| return result | |
| except Exception as e: | |
| print(e) | |
| return self.txt2img(prompt) | |
| if __name__ == '__main__': | |
| webuiapi.ControlNetUni | |
| # api = SDApi() | |
| # now_model = api.get_now_model() | |
| # print("当前使用 models :",now_model) | |
| # if "kidsmix" in now_model: | |
| # print("不需要切换模型") | |
| # else: | |
| # all_models = api.get_all_models() | |
| # model_name = None | |
| # for m in all_models: | |
| # if "kidsmix" in m.get("title"): | |
| # model_name = m.get("title") | |
| # break | |
| # current_time = datetime.datetime.now() | |
| # milliseconds = current_time.timestamp() * 1000 | |
| # print(api.set_now_model(model_name)) | |
| # current_time = datetime.datetime.now() | |
| # end_milliseconds = current_time.timestamp() * 1000 | |
| # print("耗时:" + str(int(end_milliseconds)-int(milliseconds)) + "ms") | |