翻译: 使用 GPT-4 将您的 Streamlit 应用程序提升到一个新的水平一

帮助您更快地设计、调试和优化 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 开始。然后,我通过聊天界面进行迭代,以快速尝试各种提示性想法。

  1. 它从一个好的提示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 app
  • 1 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 的兴起。我们会达到奇点吗?
  1. 转到 ChatGPT 并选择 GPT-4。您需要订阅 ChatGPT Plus 才能访问它。

  2. 将提示prompt粘贴到 ChatGPT 中。

  3. 在本地计算机上尝试生成的代码。如果您不熟悉 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 Treuille's 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? Let's 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(
    x='Sector',
    y='Impact',
    color='Sector'
)
st.altair_chart(bar_chart, use_container_width=True)

# 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(
    x='Year:O',
    y='Growth:Q',
    color=alt.value('green')
)
st.altair_chart(line_chart, use_container_width=True)

# 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 what's possible!")

# Run this script using Streamlit

要运行此应用程序:

  1. 将上述脚本保存为Python文件(例如,adrien_ai_predictor.py)。
  2. 如果尚未安装StreamlitAltair,请执行以下操作:pip install streamlit altair
  3. 在命令行中使用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/

最近更新

  1. TCP协议是安全的吗?

    2024-01-26 14:04:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-26 14:04:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-26 14:04:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-26 14:04:02       18 阅读

热门阅读

  1. Python狄拉克δ函数

    2024-01-26 14:04:02       34 阅读
  2. MySQL的数据锁表(data_locks 表)

    2024-01-26 14:04:02       31 阅读
  3. 【重点问题】攻击面发现及管理

    2024-01-26 14:04:02       28 阅读
  4. C语言连接数据库的简单示例

    2024-01-26 14:04:02       34 阅读
  5. 第二讲 C语言数据结构与变量(1)

    2024-01-26 14:04:02       26 阅读
  6. golang读取json文件

    2024-01-26 14:04:02       44 阅读
  7. golang 根据URL获取文件名

    2024-01-26 14:04:02       33 阅读
  8. GO——GPM

    2024-01-26 14:04:02       33 阅读
  9. golang 实现协程池

    2024-01-26 14:04:02       35 阅读
  10. golang map真有那么随机吗?——map遍历研究

    2024-01-26 14:04:02       26 阅读