python taipy库轻松地将数据和机器学习模型转为功能性Web应用
神奇的python库taipy
taipy 是一个开源的 Python 库,任何具有基本 Python 技能的人都可以使用。对于数据科学家、机器学习工程师和 Python 程序员来说,它是一个方便的工具。借助 Taipy,你可以轻松地将数据和机器学习模型转变为功能性的 Web 应用程序。

Taipy 的核心理念
Taipy GUI
Taipy 库提供了 GUI 类,可以在几分钟内轻松创建强大的 Web 应用程序。

当你调用 GUI 的 run() 方法时,它会启动一个 Web 服务器。Taipy 将创建的页面转换为 HTML 内容发送回客户端,使用户能够查看应用程序界面并与之交互。
场景和数据管理
让我们在 Taipy 中创建一个场景,以根据你选择的类型过滤电影数据。
此场景模拟了一个简单的管道。每次类型选择发生变化时都会提交,并输出该类型的七部最受欢迎的电影。
def filter_genre(initial_dataset: pd.DataFrame, selected_genre):
filtered_dataset = initial_dataset[initial_dataset['genres'].str.contains(selected_genre)]
filtered_data = filtered_dataset.nlargest(7, 'Popularity %')
return filtered_data

Taipy Studio
你可以使用 Visual Studio Code 中的 Taipy Studio 扩展来配置你的场景,无需任何代码。

你的配置会自动保存为 TOML 文件。
库的安装
可以直接使用 pip 来进行安装。
pip install taipy
GUI 案例
from taipy import Gui
excitement_page = """
# Welcome to Taipy
### How excited are you to try Taipy?
<|{excitement}|slider|min=1|max=100|>
My excitement level: <|{excitement}|>
"""
excitement = 100
Gui(page=excitement_page).run()
用户界面生成+场景和数据管理
现在,让我们加载此配置并在顶部添加一个用户界面以实现完整的应用程序。
import taipy as tp
import pandas as pd
from taipy import Config, Scope, Gui
# Taipy Scenario & Data Management
# Filtering function - task
def filter_genre(initial_dataset: pd.DataFrame, selected_genre):
filtered_dataset = initial_dataset[initial_dataset["genres"].str.contains(selected_genre)]
filtered_data = filtered_dataset.nlargest(7, "Popularity %")
return filtered_data
# Load the configuration made with Taipy Studio
Config.load("config.toml")
scenario_cfg = Config.scenarios["scenario"]
# Start Taipy Core service
tp.Core().run()
# Create a scenario
scenario = tp.create_scenario(scenario_cfg)
# Taipy User Interface
# Let's add a GUI to our Scenario Management for a full application
# Callback definition - submits scenario with genre selection
def on_genre_selected(state):
scenario.selected_genre_node.write(state.selected_genre)
tp.submit(scenario)
state.df = scenario.filtered_data.read()
# Get list of genres
genres = [
"Action", "Adventure", "Animation", "Children", "Comedy", "Fantasy", "IMAX"
"Romance","Sci-FI", "Western", "Crime", "Mystery", "Drama", "Horror", "Thriller", "Film-Noir","War", "Musical", "Documentary"
]
# Initialization of variables
df = pd.DataFrame(columns=["Title", "Popularity %"])
selected_genre = "Action"
## Set initial value to Action
def on_init(state):
on_genre_selected(state)
# User interface definition
my_page = """
# Film recommendation
## Choose your favorite genre
<|{selected_genre}|selector|lov={genres}|on_change=on_genre_selected|dropdown|>
## Here are the top seven picks by popularity
<|{df}|chart|x=Title|y=Popularity %|type=bar|title=Film Popularity|>
"""
Gui(page=my_page).run()

以上就是python taipy库轻松地将数据和机器学习模型转为功能性Web应用的详细内容,更多关于python taipy库的资料请关注脚本之家其它相关文章!
相关文章
Python 随机生成测试数据的模块:faker基本使用方法详解
这篇文章主要介绍了Python 随机生成测试数据的模块:faker基本使用方法,结合实例形式详细分析了Python 随机生成测试数据的模块faker基本功能、原理、使用方法及操作注意事项,需要的朋友可以参考下2020-04-04


最新评论