一、Notebook环境运行服务体验
注册魔搭社区,关联阿里云帐号会赠送100个小时的GPU加速体验。
二、公开模型
可使用社区公开模型进行调用调试
有两种调用模式:
①直接调用模型使用本地算力或云服务器算力计算。
from modelscope.utils.constant import Tasks
from modelscope.pipelines import pipeline
import cv2
pipe = pipeline(task=Tasks.text_to_image_synthesis,
model='AI-ModelScope/stable-diffusion-v1-5',
model_revision='v1.0.0')
prompt = 'a dog'
output = pipe({'text': prompt})
cv2.imwrite('result.png', output['output_imgs'][0])
from PIL import Image
from io import BytesIO
image = Image.fromarray(output['output_imgs'][0])
image.show()
②通过http的方式请求云端上已经私有化部署的大模型服务。每个用户每天有免费2000次token调用的请求限制。
import requests
import json
from PIL import Image
from io import BytesIO
url = "https://api-inference.modelscope.cn/v1/images/generations"
payload = {
"model": 'MAILAND/majicflus_v1',#ModelScope Model-Id,required
"prompt": "A golden cat"# required
}
headers = {
"Authorization": "Bearer 646dbe2d-2590-4c4c-82f3-a2bfe71cdb77",
"Content-Type": "application/json"
}
response = requests.post(url, data=json.dumps(payload, ensure_ascii=False).encode('utf-8'), headers=headers)
response_data = response.json()
image = Image.open(BytesIO(requests.get(response_data['images'][0]['url']).content))
image.save("result_image.jpg")
三、使用Notebook在线工具
可选择启动一个实例,CPU或GPU,可使用在线编译工具调试模型。
CPU为长期可使用,GPU可使用时长为赠送的100小时。
文字生成图片:
文字问答回复:
四、自定义训练模型
自定义训练模型,采用的是云端GPU的算力会有一定的收费标准。