Streamlit-FastAPI-Model-Serving 项目使用教程
项目目录结构及介绍
streamlit-fastapi-model-serving/
├── fastapi/
│ ├── app/
│ │ ├── __init__.py
│ │ ├── main.py
│ │ ├── models.py
│ │ └── routers/
│ │ ├── __init__.py
│ │ └── api.py
│ ├── Dockerfile
│ └── requirements.txt
├── streamlit/
│ ├── app.py
│ ├── Dockerfile
│ └── requirements.txt
├── docker-compose.yml
├── LICENSE
└── README.md
fastapi/:包含 FastAPI 后端服务的相关文件。app/:FastAPI 应用的主要目录。__init__.py:初始化文件。main.py:FastAPI 应用的入口文件。models.py:定义数据模型。routers/:API 路由文件。__init__.py:初始化文件。api.py:API 路由定义。
Dockerfile:FastAPI 服务的 Dockerfile。requirements.txt:FastAPI 服务的依赖文件。
streamlit/:包含 Streamlit 前端服务的相关文件。app.py:Streamlit 应用的入口文件。Dockerfile:Streamlit 服务的 Dockerfile。requirements.txt:Streamlit 服务的依赖文件。
docker-compose.yml:Docker Compose 配置文件,用于管理多个 Docker 容器。LICENSE:项目许可证。README.md:项目说明文档。
项目的启动文件介绍
FastAPI 启动文件
fastapi/app/main.py 是 FastAPI 应用的入口文件,主要包含以下内容:
from fastapi import FastAPI
from app.routers import api
app = FastAPI()
app.include_router(api.router)
Streamlit 启动文件
streamlit/app.py 是 Streamlit 应用的入口文件,主要包含以下内容:
import streamlit as st
import requests
# 前端逻辑
项目的配置文件介绍
Docker Compose 配置文件
docker-compose.yml 是 Docker Compose 的配置文件,用于定义和运行多个 Docker 容器。主要内容如下:
version: '3.8'
services:
fastapi:
build: ./fastapi
ports:
- "8000:8000"
volumes:
- ./fastapi:/app
streamlit:
build: ./streamlit
ports:
- "8501:8501"
volumes:
- ./streamlit:/app
fastapi服务:构建并运行 FastAPI 容器,端口映射为8000:8000。streamlit服务:构建并运行 Streamlit 容器,端口映射为8501:8501。
通过以上配置,可以方便地启动和管理 FastAPI 和 Streamlit 服务。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



