Docker 部署一个简单的 Streamlit 应用程序

参考文献:Deploying a Simple Streamlit app using Docker | Engineering Education (EngEd) Program | Section

        Docker 是一个虚拟化平台,旨在通过使用容器来创建、运行和部署应用程序。我们将使用 Docker 部署一个使用 Streamlit 构建的简单机器学习应用程序。

        在本教程中,我们将首先创建一个简单的机器学习模型,将其保存到 pickle 文件中以加载到我们的平台中,然后使用 Streamlit 创建其界面。创建 Streamlit 应用程序后,我们将使用 docker 来部署它。

        

Streamlit简介

        Streamlit 是一个框架,不同的机器学习工程师和数据科学家使用它从经过训练的模型构建 UI 和强大的机器学习应用程序。

        通过为用户提供交互式界面,这些应用程序可用于可视化。

        它提供了一种更简单的方法来构建图表、表格和不同的图形以满足您的应用程序的需求。它还可以利用已保存或选择到应用程序中的模型进行预测。

如何安装Streamlit

使用以下命令:

pip install streamlit

 

让我们构建streamlit应用程序

 1、文件夹结构如下:

├── Dockerfile
├── demo.xlsx
├── drive_st_test.py
├── ml.xlsx
├── requirements.txt
├── 改善v_1.xlsx

2、其中,Dockerfile文件内容如下

FROM python:3.7
WORKDIR /app

COPY requirements.txt ./requirements.txt
RUN pip install -r requirements.txt  -i https://pypi.tuna.tsinghua.edu.cn/simple

EXPOSE 8501
COPY . /app
ENTRYPOINT ["streamlit", "run"]

CMD ["drive_st_test.py"]

3.drive_st_test.py文件包含

######################
# Import libraries
######################
import pandas as pd
import numpy as np
import streamlit as st
import datetime
from datetime import datetime
from datetime import timedelta

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns

from plotly import subplots
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import plotly.express as px
import plotly.figure_factory as ff

#加载streamlit pyecharts
from pyecharts.charts import *
from pyecharts.faker import Faker
import streamlit_echarts
from pyecharts import options as opts
from pyecharts.globals import ThemeType

st.set_page
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值