网站建设开发公司微信公众号开发,网站多久备份一次,网站设计制作售价多少钱,wordpress转中文版帮助您更快地设计、调试和优化 Streamlit 应用的专业技巧
设计和扩展 Streamlit 应用程序可能是一项艰巨的任务#xff01;作为开发人员#xff0c;我们经常面临一些挑战#xff0c;例如设计良好的 UI、快速调试我们的应用程序以及快速制作它们。
如果有一个工具可以加快速…帮助您更快地设计、调试和优化 Streamlit 应用的专业技巧
设计和扩展 Streamlit 应用程序可能是一项艰巨的任务作为开发人员我们经常面临一些挑战例如设计良好的 UI、快速调试我们的应用程序以及快速制作它们。
如果有一个工具可以加快速度呢
这个工具有一个名字叫做GPT-4 在本指南中我们将介绍
ChatGPT 的演变从它的兴起到理解大型语言模型 large language models的可信度。使用 GPT-4 进行闪电般的应用程序开发包括提示提示和笔记本电脑到 Streamlit 应用程序的转换。使用 GPT-4 进行高效的调试和代码库更改。使用 GPT-4 优化应用程序性能而且没有压力
无论您是经验丰富的 Streamlit 开发人员还是刚刚起步本指南都将帮助您利用 GPT-4 更快地构建更好的应用程序。
ChatGPT的兴起
2022年11月OpenAI发布ChatGPT立即风靡全球
这是第一次人们可以与人工智能就任何主题进行有意义的对话并将其用于教育、创意写作、法律研究、个人辅导、代码创建等任务。
截至 2023 年 1 月它拥有超过 1 亿用户使其成为有史以来增长最快的平台。
但您可能想知道由 GPT-3.5 提供支持的早期 ChatGPT 是如何设计 Streamlit 应用程序的
它实际上远非完美通常不准确并且需要大量的手动微调才能使应用程序正确。 GPT-4 于 2023 年 3 月发布显着改善了短期记忆、参数和创造力导致比 GPT-3.5 更准确和更具创造性的反应。
LLM的可信度如何
尽管 GPT-4 提高了其可靠性但与其他 LLM 一样它仍然会产生误导性或虚构的输出称为幻觉hallucinations这里有一篇关于它们的好读物。
这些可以归因于缺乏最新数据、训练数据中的偏差以及不明确或模棱两可的提示。
您通常可以通过迭代优化提示来解决这些问题直到达到所需的结果。稍后我们将介绍减少幻觉的提示技巧。我还将解释如何通过 GPT-4 的 Code Interpreter 提高数据的鲁棒性。
1使用 GPT-4 加快 Streamlit 应用程序开发
1.1 — GPT-4 作为任何应用程序的起点
如今在设计任何 Streamlit 应用程序时我通常从 GPT-4 开始。然后我通过聊天界面进行迭代以快速尝试各种提示性想法。
它从一个好的提示prompt开始 Write a humorous Streamlit app about how Adrien Treuille, an LLM genius and developer extraordinaire at Snowflake, is an LLM genius. Include an Altair bar chart and an Altair line chart. Include at least 2 numerical input sliders in the sidebar 1 slider for the Altair bar chart at the top of the app1 slider for the Altair line chart at the bottom of the app The app should allow Adrien to predict the rise of generative AI in the next 5 years. Will we reach singularity? 写一个幽默的 Streamlit 应用程序讲述 Snowflake 的 LLM 天才和开发人员 Adrien Treuille 如何成为 LLM 天才。 包括 Altair 条形图和 Altair 折线图。在边栏中包含至少 2 个数字输入滑块
应用程序顶部的 1 个 Altair 条形图滑块应用程序底部的 1 个 Altair 折线图滑块 该应用程序应该允许 Adrien 预测未来 5 年生成式 AI 的兴起。我们会达到奇点吗 转到 ChatGPT 并选择 GPT-4。您需要订阅 ChatGPT Plus 才能访问它。 将提示prompt粘贴到 ChatGPT 中。 在本地计算机上尝试生成的代码。如果您不熟悉 Streamlit请按照此处的安装步骤操作。
让我们在下面查看 GPT-4 生成的 Streamlit 应用程序 当然可以创建一个有趣的Streamlit应用程序关于Adrien Treuille他是Snowflake的LLM天才和开发者可以是探索生成式AI潜力的有趣方式。该应用程序将包括两个Altair图表和用于与它们交互的滑块。以下是创建这种应用程序的Python脚本大纲
import streamlit as st
import altair as alt
import pandas as pd
import numpy as np# App title
st.title(Adrien Treuille: The LLM Genius Predictor)# Introduction text
st.write(Welcome to the Adrien Treuilles Generative AI Predictor! Join Adrien, our LLM genius and developer extraordinaire at Snowflake, as he predicts the rise of generative AI in the next 5 years. Will we reach the singularity? Lets find out!)# Sidebar title
st.sidebar.title(Controls)# Slider for the Bar Chart
ai_impact st.sidebar.slider(Predicted Impact of AI on Different Sectors (1-100), 1, 100, 50)# Creating a DataFrame for Bar Chart
sectors [Technology, Healthcare, Finance, Education, Entertainment]
impact [ai_impact * np.random.uniform(0.8, 1.2) for _ in sectors]
bar_data pd.DataFrame({Sector: sectors, Impact: impact})# Altair Bar Chart
bar_chart alt.Chart(bar_data).mark_bar().encode(xSector,yImpact,colorSector
)
st.altair_chart(bar_chart, use_container_widthTrue)# Spacer
st.write(---)# Slider for the Line Chart
ai_growth st.sidebar.slider(AI Growth Rate Over Next 5 Years (1-20%), 1, 20, 10)# Creating a DataFrame for Line Chart
years np.arange(2024, 2029)
growth [(1 ai_growth/100)**i for i in range(5)]
line_data pd.DataFrame({Year: years, Growth: growth})# Altair Line Chart
line_chart alt.Chart(line_data).mark_line().encode(xYear:O,yGrowth:Q,coloralt.value(green)
)
st.altair_chart(line_chart, use_container_widthTrue)# Footer
st.write(Disclaimer: This app is for entertainment purposes only and may not accurately predict the future of AI, but with Adrien Treuille on board, who knows whats possible!)# Run this script using Streamlit
要运行此应用程序
将上述脚本保存为Python文件例如adrien_ai_predictor.py。如果尚未安装Streamlit和Altair请执行以下操作pip install streamlit altair。在命令行中使用Streamlit运行应用程序streamlit run adrien_ai_predictor.py。
该应用程序以幽默的方式允许Adrien Treuille被描绘为人工智能领域的先知预测人工智能对各个领域的影响以及未来五年内的增长都以一种充满趣味和幽默的语气强调了人工智能未来的不可预测性和令人兴奋的特性。
1.2 – 简化应用设计的提示prompt
“Garbage in, Garbage out” “垃圾进垃圾出”很适用于提示prompting。代码质量很大程度上取决于您输入的提示
那么什么是设计 Streamlit 应用程序的好提示呢
在上面的提示中我的指示很清楚。我指定了语气、上下文、应用程序功能并添加了我想查看的图表和小部件。
以下是帮助您入门的 5 个提示提示 通过遵循这些简单的准则您应该能够更快地获得所需的结果从而减少在 ChatGPT 界面中来回对话的需要。
代码
https://github.com/zgpeace/pets-name-langchain/tree/develop
参考
https://blog.streamlit.io/take-your-streamlit-apps-to-the-next-level-with-gpt-4/