在高性能应用服务-》算力管理 新建一个算力服务器
提供的AI模型包括Stable Diffusion WebUI,ChatGLM2 6B,Llama2 7B, Llama2 13B和Stable Diffusion ComfyUI。这里图片生成服务我们使用Stable Diffusion WebUI。
接着在区域里选择服务器所在地区。国外的服务优势在于下载模型快速,但是从国内ip访问延迟时间大。国内节点下载模型慢一些,但是离我们访问端近。
如果你的账号是传统类型,需要提交工单升级下成标准类型
于是这里创建了一个名叫 my-hal-sora的服务器
接着点击右下角的JupterLab接入python代码编辑界面
打开jupyter这里有代码编辑模版,这是官方提供的一些测试命令
然后在这里可以下大模型
https://cloud.tencent.com/act/pro/hai?from=21361
这里有官方提供的1元使用8小时的算力服务体验券,搭建的时候可以看看这里
我们的代码实例如下,就是向你搭建好的服务端口发起一个Post请求,请求参数下你要生成图片的文字,然后response会返回图片的base64编码字符串,对这段base64解码就得到二进制图片。
import json
import base64
import requests
your_ip = '0.0.0.0' # HAI服务器IP地址
your_port = 7862 # SD api 监听的端口
def submit_post(url: str,data: dict):
"""
Submit a POST request to the given URL with the given data.
"""
return requests.post(url,data=json.dumps(data))
def save_encoded_image(b64_image: str,output_path: str):
"""
Save the given image to the given output path.
"""
with open(output_path,"wb") as image_file:
image_file.write(base64.b64decode(b64_image))
if __name__ == '__main__':
# /sdapi/v1/txt2img
txt2img_url = f'http://{your_ip}:{your_port}/sdapi/v1/txt2img'
data = {
'prompt': 'a pretty cat,cyberpunk art,kerem beyit,very cute robot zen,Playful,Independent,beeple |',
'negative_prompt':'(deformed,distorted,disfigured:1.0),poorly drawn,bad anatomy,wrong anatomy,extra limb,missing limb,floating limbs,(mutated hands and fingers:1.5),disconnected limbs,mutation,mutated,ugly,disgusting,blurry,amputation,flowers,human,man,woman',
'Steps':50,
'Seed':1791574510
}
response = submit_post(txt2img_url,data)
save_encoded_image(response.json()['images'][0],'cat.png')
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。