import diffusers, torch, os
from time import strftime, localtime
model_id = "CompVis/stable-diffusion-v1-4"
device = torch.device("cuda")
pipe = diffusers.StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
pipe = pipe.to(device)
image = pipe(prompt).images[0]
timeprint = strftime("%Y%m%d%H%M%S", localtime())
fldpath = os.path.join('/mnt/', 'xxx/img')
if not os.path.exists(fldpath):
os.mkdir(fldpath)
img_filenm = f'{timeprint}.png'
image.save(os.path.join(fldpath, img_filenm))
print(f'{timeprint}.png')
4. userinput_write_pyfile.py:
defuserinput_write_pyfile(user_input,local_put_path):'''
- 将用户输入的文字信息写入远程py待执行文件中
'''import os
f =open(local_put_path,'r')
index =0
lines =[]for line in f.readlines():
index +=1if index ==3:
prompt =f'prompt = "{
user_input}"'
lines.append(prompt)
lines.append(line)
usr_path = os.path.join(os.path.expanduser('~'),'Desktop/SSH/upload')
pyfilepath = os.path.join(usr_path,'autocover.py')
pf =open(pyfilepath,'w')for line in lines:
pf.write(''.join(line))
pf.close()return pyfilepath