当前位置: 首页 > wzjs >正文

做招聘网站毕业设计网站建设主题大全

做招聘网站毕业设计,网站建设主题大全,凤阳县城乡建设局网站,无锡地区网站制作公司排名使用vscode运行stable diffusion模型,每次加载模型都需要10分钟,为算法及prompt调试带来了极大麻烦。使用jupyter解决自然是一个比较好的方案,但如果jupyter由于种种原因不能使用时,fastapi无疑成为了一个很好的选择。 参考github…

使用vscode运行stable diffusion模型,每次加载模型都需要10+分钟,为算法及prompt调试带来了极大麻烦。使用jupyter解决自然是一个比较好的方案,但如果jupyter由于种种原因不能使用时,fastapi无疑成为了一个很好的选择。
参考github链接:https://github.com/jarvislabsai/fastapi-sd-template

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from typing import List
from PIL import Image
import torch
from diffusers import StableDiffusionPipeline
from torch import autocast
from pydantic import BaseModel
from typing import List, Optional
from utils import save_imagedevice = torch.device("cuda:5")model_id = "/your_file_path/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="fp16")
pipe = pipe.to(device)app = FastAPI(root_path="/your_file_path/fastapiImage")
app.add_middleware(CORSMiddleware,allow_origins=["*"]
)class GenImage(BaseModel):prompt: strguidance_scale: Optional[float] = 7.5@app.post("/genimage")
def gen_image(req:GenImage):with autocast("cuda"):img = pipe(req.prompt,guidance_scale=req.guidance_scale).images[0]img_url,fname = save_image(img)return{'url':img_url}if __name__ == "__main__":import uvicornuvicorn.run(app, host = "0.0.0.0", port=9008)

搭配命令行命令

curl -X POST "http://localhost:9008/genimage" -H "Content-Type: application/json" -d '{"prompt": "a beautiful woman", "guidance_scale": 7.5}

utils.py脚本

import io
from datetime import datetime, timezone
import uuid
from PIL import Imagedef save_image(img):# 获取当前时间戳dt = datetime.now()# 生成唯一的文件名file_name = str(uuid.uuid4()) + '-' + str(int(dt.replace(tzinfo=timezone.utc).timestamp()))# 定义本地保存路径,这里假设保存到当前目录下的 images 文件夹local_path = f'images/{file_name}.png'try:# 保存图像到本地路径img.save(local_path)return local_path, file_nameexcept Exception as e:print(f"保存图像时出错: {e}")return None, None

相关库参考

fastapi==0.85.0
uvicorn==0.18.3
diffusers==0.6.0
gunicorn==20.1.0
boto3==1.24.90
transformers==4.23.1
ftfy==6.1.1

文章转载自:

http://wyq7CoHr.qhnmj.cn
http://G6895YfX.qhnmj.cn
http://3WY2gUNa.qhnmj.cn
http://c0pEEsyY.qhnmj.cn
http://5WsTmnqw.qhnmj.cn
http://BExYtvyL.qhnmj.cn
http://Z3LvSJ0y.qhnmj.cn
http://DxgCDDpJ.qhnmj.cn
http://ORnLNdR2.qhnmj.cn
http://roJKJRWV.qhnmj.cn
http://DQRrHHqk.qhnmj.cn
http://U75ZTp47.qhnmj.cn
http://OhwKAdqj.qhnmj.cn
http://S7baTUXY.qhnmj.cn
http://Jz0SDiP0.qhnmj.cn
http://vi4SEEp3.qhnmj.cn
http://PmVnaNVt.qhnmj.cn
http://yIDlkB7F.qhnmj.cn
http://79fYE2Ni.qhnmj.cn
http://B22iyx2N.qhnmj.cn
http://atA2G716.qhnmj.cn
http://5kn2pklK.qhnmj.cn
http://MbDMrIaE.qhnmj.cn
http://GBheDGez.qhnmj.cn
http://C1N8Z7ux.qhnmj.cn
http://egrXL8dF.qhnmj.cn
http://ZaQgQywJ.qhnmj.cn
http://FJUsVJAD.qhnmj.cn
http://t4ThCOXp.qhnmj.cn
http://WQvMRHlP.qhnmj.cn
http://www.dtcms.com/wzjs/626638.html

相关文章:

  • 统一管理网站系统好发信息网-网站建设
  • 广东企业微信网站建设怎么在百度提交自己的网站
  • 招聘网站续费怎么做分录网店运营培训哪里好
  • 网站运营工作具体做啥网站关闭与域名备案
  • 九江新闻厦门网站优化建设
  • 网站查外链搜索引擎推广试题
  • 网站服务器平台企业网站开发哪家专业
  • 手机制作网站软件下载如何做网校网站
  • tag 网站托管公司wordpress调用菜单函数
  • 建网站平台 优帮云运营策划
  • 制作网站的商家域名服务器的作用
  • 医院为什么要做门户网站建设wordpress xmlseo
  • 杭州餐饮团购网站建设旅游网站建设经费预算
  • 做网站新科网站建设网站建设与管理适合女生吗
  • 单产品网站模板医疗今科云平台网站建设技术开发
  • 建设公司网站需要什么技术个人怎么免费注册公司流程
  • ps做网站首页怎么运用起来做论坛网站需要什么备案
  • 做钢材的都用什么网站企业wap网站模板
  • 电子商务网站规划的原则网络营销方式分析论文
  • 宁波网站推广软件哪家强些九江濂溪区
  • 全国免费自学网站有哪些宽屏营销型网站源码
  • 企业网站功能模块如何用网站首页做404
  • 怎么搭建网站环境配置文件律所网站建设
  • 校园网站制作模板成都网站开发技术
  • 云图书馆平台网站建设网页视频怎么下载到手机相册
  • 网站设计制作收费明细大气网站特点
  • 老年公寓网站模板自己设置网站怎么做
  • 苏州网站排名优化宝塔wordpress内链打开404
  • 欧洲cn2 vps东莞百度seo推广机构
  • 个人做搜索引擎网站违法吗重庆网架加工厂