FastAPI for Machine Learning: Live coding an ML web application
https://www.bilibili.com/video/BV1kC411b7Se/?spm_id_from=333.788.videopod.sections&vd_source=57e261300f39bf692de396b55bf8c41b
翻译:FastAPI用于机器学习:现场编码一个ML Web应用程序。欢迎!加入我们的现场研讨会,您可以跟随FastAPI的创建者Sebastián Ramírez一起构建自己的AI图像生成Web应用程序!他将概述FastAPI Web框架的核心组件,并且他的应用程序将利用新发布的Stable Diffusion文本到图像深度学习模型。
https://www.linkedin.com/events/fastapiformachinelearning-livec7006333565051293696/comments/
Join us for a live workshop where you can follow along with the creator of FastAPI Sebastián Ramírez to build your very own AI image generation web application! He will outline the core components of the FastAPI web framework, and his application will leverage the newly-released Stable Diffusion text-to-image deep learning model.
Who should attend the event?
- Learners who want to build AI applications with FastAPI
- Learners who want to understand FastAPI’s architecture
- Learners who are interested in Python API web frameworks
Why should you attend the event?
- To learn how to build ML web applications in Python
- To see an example of a Stable Diffusion application
- To learn about FastAPI directly from the creator!
https://github.com/FourthBrain/FastAPI-for-Machine-Learning-Live-Demo/blob/main/main.py
This repository contains the files to build your very own AI image generation web application! Outlined are the core components of the FastAPI web framework, and application leverage the newly-released Stable Diffusion text-to-image deep learning model.
📺 You can checkout the full video here!
流式内存响应图片给客户端
import iofrom fastapi import FastAPI from fastapi.responses import FileResponse, StreamingResponse from pydantic import BaseModelfrom ml import obtain_imageapp = FastAPI()@app.get("/") def read_root():return {"Hello": "World"}@app.get("/items/{item_id}") def read_item(item_id: int):return {"item_id": item_id}class Item(BaseModel):name: strprice: floattags: list[str] = []@app.post("/items/") def create_item(item: Item):return item@app.get("/generate") def generate_image(prompt: str,*,seed: int | None = None,num_inference_steps: int = 50,guidance_scale: float = 7.5 ):image = obtain_image(prompt,num_inference_steps=num_inference_steps,seed=seed,guidance_scale=guidance_scale,)image.save("image.png")return FileResponse("image.png")@app.get("/generate-memory") def generate_image_memory(prompt: str,*,seed: int | None = None,num_inference_steps: int = 50,guidance_scale: float = 7.5 ):image = obtain_image(prompt,num_inference_steps=num_inference_steps,seed=seed,guidance_scale=guidance_scale,)memory_stream = io.BytesIO()image.save(memory_stream, format="PNG")memory_stream.seek(0)return StreamingResponse(memory_stream, media_type="image/png")