Upload 2 files
Browse files- app.py +143 -49
- config.yaml +22 -0
app.py
CHANGED
|
@@ -8,13 +8,10 @@
|
|
| 8 |
from matplotlib.font_manager import FontProperties
|
| 9 |
myfont=FontProperties(fname='/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/code_interpreter/rawdata/SimHei.ttf')
|
| 10 |
sns.set_style('whitegrid',{'font.sans-serif':['simhei','Arial']})
|
| 11 |
-
|
| 12 |
-
1. openai key, bing key.
|
| 13 |
-
1. proxy
|
| 14 |
-
1.
|
| 15 |
|
| 16 |
'''
|
| 17 |
-
# TODO:1.
|
| 18 |
|
| 19 |
import requests
|
| 20 |
from codeinterpreterapi import CodeInterpreterSession, File
|
|
@@ -33,34 +30,28 @@ from pathlib import Path
|
|
| 33 |
from matplotlib.font_manager import FontProperties
|
| 34 |
import seaborn as sns
|
| 35 |
from time import sleep
|
|
|
|
| 36 |
|
| 37 |
os.environ["OPENAI_API_KEY"] = os.environ['user_token']
|
| 38 |
openai.api_key = os.environ['user_token']
|
|
|
|
| 39 |
|
| 40 |
-
# #* 如果碰到接口问题,可以启用如下设置。
|
| 41 |
# openai.proxy = {
|
| 42 |
# "http": "http://127.0.0.1:7890",
|
| 43 |
# "https": "http://127.0.0.1:7890"
|
| 44 |
# }
|
| 45 |
|
|
|
|
| 46 |
# layout settings.
|
| 47 |
st.title("个人大语言模型商业智能中心")
|
| 48 |
st.subheader("Artificial Intelligence Backend Center for Individuals")
|
| 49 |
|
| 50 |
-
# st.image("./知识星球收入.jpg")
|
| 51 |
-
# tab1, tab2 = st.tabs(["传统模式", "数据模型"])
|
| 52 |
-
# with tab1:
|
| 53 |
-
col1, col2 = st.columns(spec=[1, 2])
|
| 54 |
-
radio_1 = col1.radio(label='ChatGPT版本', options=[
|
| 55 |
-
'GPT-3.5', 'GPT-4.0'], horizontal=True, label_visibility='visible')
|
| 56 |
-
radio_2 = col2.radio(label='模式选择', options=[
|
| 57 |
-
'核心模式', '联网模式', '数据模式'], horizontal=True, label_visibility='visible')
|
| 58 |
-
|
| 59 |
# with tab2:
|
| 60 |
def upload_file(uploaded_file):
|
| 61 |
if uploaded_file is not None:
|
| 62 |
filename = uploaded_file.name
|
| 63 |
-
st.write(filename)
|
| 64 |
try:
|
| 65 |
if '.csv' in filename:
|
| 66 |
csv_file = pd.read_csv(uploaded_file)
|
|
@@ -81,14 +72,15 @@ def upload_file(uploaded_file):
|
|
| 81 |
# ! 必须用这种格式读入内容,然后才可以写入temporary文件夹中。
|
| 82 |
# output_temporary_file.write(uploaded_file.getvalue())
|
| 83 |
output_temporary_file.write(uploaded_file.getvalue())
|
|
|
|
|
|
|
| 84 |
|
| 85 |
return None
|
| 86 |
|
| 87 |
|
| 88 |
-
bing_search_api_key = os.environ['
|
| 89 |
bing_search_endpoint = 'https://api.bing.microsoft.com/v7.0/search'
|
| 90 |
|
| 91 |
-
|
| 92 |
def search(query):
|
| 93 |
# Construct a request
|
| 94 |
# mkt = 'en-EN'
|
|
@@ -110,7 +102,6 @@ def search(query):
|
|
| 110 |
|
| 111 |
# openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 112 |
|
| 113 |
-
# async def main():
|
| 114 |
async def text_mode():
|
| 115 |
# Set a default model
|
| 116 |
if "openai_model" not in st.session_state:
|
|
@@ -148,7 +139,7 @@ async def text_mode():
|
|
| 148 |
full_response = ""
|
| 149 |
|
| 150 |
if radio_2 == '联网模式':
|
| 151 |
-
|
| 152 |
input_message = prompt
|
| 153 |
internet_search_result = search(input_message)
|
| 154 |
search_prompt = [
|
|
@@ -175,6 +166,7 @@ async def text_mode():
|
|
| 175 |
message_placeholder.markdown(full_response)
|
| 176 |
st.session_state.messages.append(
|
| 177 |
{"role": "assistant", "content": full_response})
|
|
|
|
| 178 |
|
| 179 |
if radio_2 == '核心模式':
|
| 180 |
print('GPT only starts!!!')
|
|
@@ -185,7 +177,8 @@ async def text_mode():
|
|
| 185 |
# {"role": m["role"], "content": m["content"]}
|
| 186 |
# for m in st.session_state.messages
|
| 187 |
# ],
|
| 188 |
-
messages=[{'role': 'system', 'content': 'you are ChatGPT'}, {
|
|
|
|
| 189 |
stream=True,
|
| 190 |
):
|
| 191 |
full_response += response.choices[0].delta.get(
|
|
@@ -198,9 +191,9 @@ async def text_mode():
|
|
| 198 |
|
| 199 |
|
| 200 |
async def data_mode():
|
| 201 |
-
|
| 202 |
uploaded_file_path = './upload.csv'
|
| 203 |
-
# st.write(f"passed file path in data_mode: {uploaded_file_path}")
|
| 204 |
# tmp1 = pd.read_csv('./upload.csv')
|
| 205 |
# st.write(tmp1[:5])
|
| 206 |
|
|
@@ -226,23 +219,22 @@ async def data_mode():
|
|
| 226 |
|
| 227 |
with st.chat_message("assistant"):
|
| 228 |
async with CodeInterpreterSession() as session:
|
| 229 |
-
myfont=FontProperties(fname='./SimHei.ttf')
|
| 230 |
-
print(myfont)
|
| 231 |
# user_request = "对于文件中的'SepalLengthCm’数据给我一个'直方图',提供图表,并给出分析结果"
|
| 232 |
#! 可以用设定dpi=300来输出高质量的图表。(注:图的解析度dpi设定为300)
|
| 233 |
environ_settings = """【背景要求】如果我没有告诉你任何定制化的要求,那么请你按照以下的默认要求来回答:
|
| 234 |
-------------------------------------------------------------------------
|
| 235 |
1. 你需要用提问的语言来回答(如:中文提问你就用中文来回答,英文提问你就用英文来回答)。
|
| 236 |
-
2. 如果要求你输出图表,那么图的解析度dpi需要设定为
|
| 237 |
-
3.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
-------------------------------------------------------------------------
|
| 239 |
""" # seaborn中的palette参数可以设定图表的颜色,选项包括:deep, muted, pastel, bright, dark, colorblind,Spectral。更多参数可以参考:https://seaborn.pydata.org/generated/seaborn.color_palette.html。
|
| 240 |
|
| 241 |
# uploaded_file_path = upload_file()
|
| 242 |
|
| 243 |
-
## 设置中文字体显示。
|
| 244 |
-
# sns.set_style({'font.sans-serif':['myfont']})
|
| 245 |
-
|
| 246 |
user_request = environ_settings + "\n\n" + \
|
| 247 |
"你需要完成以下任务:\n\n" + prompt + "\n\n" \
|
| 248 |
f"注:文件位置在{uploaded_file_path}"
|
|
@@ -268,32 +260,134 @@ async def data_mode():
|
|
| 268 |
# st.image(file.get_image()) #! working.
|
| 269 |
# * 注意这里的设定,可以提高图片的精细程度。
|
| 270 |
st.image(file.get_image(), width=None,
|
| 271 |
-
|
| 272 |
|
| 273 |
# message_placeholder.markdown(full_response + "▌") ## orignal code.
|
| 274 |
# message_placeholder.markdown(full_response) ## orignal code.
|
| 275 |
st.write(full_response)
|
| 276 |
status.update(label='complete', state='complete')
|
| 277 |
-
|
| 278 |
-
#
|
|
|
|
|
|
|
| 279 |
|
| 280 |
await session.astop() # ! 确认需要关闭。
|
| 281 |
-
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
if __name__ == "__main__":
|
| 284 |
import asyncio
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
|
|
|
| 8 |
from matplotlib.font_manager import FontProperties
|
| 9 |
myfont=FontProperties(fname='/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/code_interpreter/rawdata/SimHei.ttf')
|
| 10 |
sns.set_style('whitegrid',{'font.sans-serif':['simhei','Arial']})
|
| 11 |
+
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
'''
|
| 14 |
+
# TODO:1. Chinese display isssue. 2. account system.
|
| 15 |
|
| 16 |
import requests
|
| 17 |
from codeinterpreterapi import CodeInterpreterSession, File
|
|
|
|
| 30 |
from matplotlib.font_manager import FontProperties
|
| 31 |
import seaborn as sns
|
| 32 |
from time import sleep
|
| 33 |
+
import streamlit_authenticator as stauth
|
| 34 |
|
| 35 |
os.environ["OPENAI_API_KEY"] = os.environ['user_token']
|
| 36 |
openai.api_key = os.environ['user_token']
|
| 37 |
+
# os.environ["VERBOSE"] = "True" # 可以看到具体的错误?
|
| 38 |
|
| 39 |
+
# # #* 如果碰到接口问题,可以启用如下设置。
|
| 40 |
# openai.proxy = {
|
| 41 |
# "http": "http://127.0.0.1:7890",
|
| 42 |
# "https": "http://127.0.0.1:7890"
|
| 43 |
# }
|
| 44 |
|
| 45 |
+
|
| 46 |
# layout settings.
|
| 47 |
st.title("个人大语言模型商业智能中心")
|
| 48 |
st.subheader("Artificial Intelligence Backend Center for Individuals")
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# with tab2:
|
| 51 |
def upload_file(uploaded_file):
|
| 52 |
if uploaded_file is not None:
|
| 53 |
filename = uploaded_file.name
|
| 54 |
+
st.write(filename) # print out the whole file name to validate.
|
| 55 |
try:
|
| 56 |
if '.csv' in filename:
|
| 57 |
csv_file = pd.read_csv(uploaded_file)
|
|
|
|
| 72 |
# ! 必须用这种格式读入内容,然后才可以写入temporary文件夹中。
|
| 73 |
# output_temporary_file.write(uploaded_file.getvalue())
|
| 74 |
output_temporary_file.write(uploaded_file.getvalue())
|
| 75 |
+
# st.write(uploaded_file_path) # * 可以查看文件是否真实存在,然后是否可以
|
| 76 |
+
# st.write('Now file saved successfully.')
|
| 77 |
|
| 78 |
return None
|
| 79 |
|
| 80 |
|
| 81 |
+
bing_search_api_key = os.environ['user_token']
|
| 82 |
bing_search_endpoint = 'https://api.bing.microsoft.com/v7.0/search'
|
| 83 |
|
|
|
|
| 84 |
def search(query):
|
| 85 |
# Construct a request
|
| 86 |
# mkt = 'en-EN'
|
|
|
|
| 102 |
|
| 103 |
# openai.api_key = st.secrets["OPENAI_API_KEY"]
|
| 104 |
|
|
|
|
| 105 |
async def text_mode():
|
| 106 |
# Set a default model
|
| 107 |
if "openai_model" not in st.session_state:
|
|
|
|
| 139 |
full_response = ""
|
| 140 |
|
| 141 |
if radio_2 == '联网模式':
|
| 142 |
+
print('联网模式入口,prompt:', prompt)
|
| 143 |
input_message = prompt
|
| 144 |
internet_search_result = search(input_message)
|
| 145 |
search_prompt = [
|
|
|
|
| 166 |
message_placeholder.markdown(full_response)
|
| 167 |
st.session_state.messages.append(
|
| 168 |
{"role": "assistant", "content": full_response})
|
| 169 |
+
st.session_state.messages = []
|
| 170 |
|
| 171 |
if radio_2 == '核心模式':
|
| 172 |
print('GPT only starts!!!')
|
|
|
|
| 177 |
# {"role": m["role"], "content": m["content"]}
|
| 178 |
# for m in st.session_state.messages
|
| 179 |
# ],
|
| 180 |
+
messages=[{'role': 'system', 'content': 'you are ChatGPT'}, {
|
| 181 |
+
'role': 'user', 'content': prompt}],
|
| 182 |
stream=True,
|
| 183 |
):
|
| 184 |
full_response += response.choices[0].delta.get(
|
|
|
|
| 191 |
|
| 192 |
|
| 193 |
async def data_mode():
|
| 194 |
+
print('数据分析模式启动!')
|
| 195 |
uploaded_file_path = './upload.csv'
|
| 196 |
+
# # st.write(f"passed file path in data_mode: {uploaded_file_path}")
|
| 197 |
# tmp1 = pd.read_csv('./upload.csv')
|
| 198 |
# st.write(tmp1[:5])
|
| 199 |
|
|
|
|
| 219 |
|
| 220 |
with st.chat_message("assistant"):
|
| 221 |
async with CodeInterpreterSession() as session:
|
|
|
|
|
|
|
| 222 |
# user_request = "对于文件中的'SepalLengthCm’数据给我一个'直方图',提供图表,并给出分析结果"
|
| 223 |
#! 可以用设定dpi=300来输出高质量的图表。(注:图的解析度dpi设定为300)
|
| 224 |
environ_settings = """【背景要求】如果我没有告诉你任何定制化的要求,那么请你按照以下的默认要求来回答:
|
| 225 |
-------------------------------------------------------------------------
|
| 226 |
1. 你需要用提问的语言来回答(如:中文提问你就用中文来回答,英文提问你就用英文来回答)。
|
| 227 |
+
2. 如果要求你输出图表,那么图的解析度dpi需要设定为300。图尽量使用seaborn库。seaborn库的参数设定:sns.set(rc={'axes.facecolor':'#FFF9ED','figure.facecolor':'#FFF9ED'}, palette='dark'。
|
| 228 |
+
3. 在图上显示中文时,需要按如下要求操作:
|
| 229 |
+
myfont=FontProperties(fname='/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/code_interpreter/SimHei.ttf')
|
| 230 |
+
plt.rcParams['font.sans-serif'] = ['myfont']
|
| 231 |
+
plt.rcParams['font.family']='sans-serif'
|
| 232 |
+
sns.set_style({'font.sans-serif':['myfont']})
|
| 233 |
-------------------------------------------------------------------------
|
| 234 |
""" # seaborn中的palette参数可以设定图表的颜色,选项包括:deep, muted, pastel, bright, dark, colorblind,Spectral。更多参数可以参考:https://seaborn.pydata.org/generated/seaborn.color_palette.html。
|
| 235 |
|
| 236 |
# uploaded_file_path = upload_file()
|
| 237 |
|
|
|
|
|
|
|
|
|
|
| 238 |
user_request = environ_settings + "\n\n" + \
|
| 239 |
"你需要完成以下任务:\n\n" + prompt + "\n\n" \
|
| 240 |
f"注:文件位置在{uploaded_file_path}"
|
|
|
|
| 260 |
# st.image(file.get_image()) #! working.
|
| 261 |
# * 注意这里的设定,可以提高图片的精细程度。
|
| 262 |
st.image(file.get_image(), width=None,
|
| 263 |
+
output_format='PNG')
|
| 264 |
|
| 265 |
# message_placeholder.markdown(full_response + "▌") ## orignal code.
|
| 266 |
# message_placeholder.markdown(full_response) ## orignal code.
|
| 267 |
st.write(full_response)
|
| 268 |
status.update(label='complete', state='complete')
|
| 269 |
+
|
| 270 |
+
# TODO: 确认是否要记录所有的full response。
|
| 271 |
+
st.session_state.messages.append(
|
| 272 |
+
{"role": "assistant", "content": full_response})
|
| 273 |
|
| 274 |
await session.astop() # ! 确认需要关闭。
|
| 275 |
+
# st.session_state.messages.append({"role": "assistant", "content": full_response})
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
# authentication.
|
| 279 |
+
import yaml
|
| 280 |
+
from yaml.loader import SafeLoader
|
| 281 |
+
with open('/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/code_interpreter/config.yaml') as file:
|
| 282 |
+
config = yaml.load(file, Loader=SafeLoader)
|
| 283 |
+
authenticator = stauth.Authenticate(
|
| 284 |
+
config['credentials'],
|
| 285 |
+
config['cookie']['name'],
|
| 286 |
+
config['cookie']['key'],
|
| 287 |
+
config['cookie']['expiry_days'],
|
| 288 |
+
config['preauthorized']
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
name, authentication_status, username = authenticator.login('Login', 'sidebar')
|
| 292 |
+
|
| 293 |
+
if authentication_status:
|
| 294 |
+
with st.sidebar:
|
| 295 |
+
# st.markdown(
|
| 296 |
+
# """
|
| 297 |
+
# <style>
|
| 298 |
+
# [data-testid="stSidebar"][aria-expanded="true"]{
|
| 299 |
+
# min-width: 600x;
|
| 300 |
+
# max-width: 600px;
|
| 301 |
+
# }
|
| 302 |
+
# """,
|
| 303 |
+
# unsafe_allow_html=True,
|
| 304 |
+
# )
|
| 305 |
+
st.header(f'**欢迎 **{name}** 来到人工智能的世界** ♠')
|
| 306 |
+
st.write(f'_Welcome and Hope U Enjoy Staying Here!_')
|
| 307 |
+
authenticator.logout('登出', 'sidebar')
|
| 308 |
+
# with st.header(body="欢迎"):
|
| 309 |
+
# st.markdown("# 欢迎使用大语言模型商业智能中心")
|
| 310 |
+
# with st.expander(label=("**重要的使用注意事项**"), expanded=True):
|
| 311 |
+
with st.container():
|
| 312 |
+
st.markdown("#### 重要的使用注意事项")
|
| 313 |
+
with st.text(body="说明"):
|
| 314 |
+
st.markdown("* 重启一轮新对话时,只需要刷新页面(按Ctrl/Command + R)即可。")
|
| 315 |
+
with st.text(body="说明"):
|
| 316 |
+
st.markdown("* 为了保护数据与隐私,所有对话均不会被保持,刷新页面立即删除。敬请放心。")
|
| 317 |
+
with st.text(body="说明"):
|
| 318 |
+
st.markdown("* 'GPT-4'回答质量极佳,但速度缓慢、且不支持长文。建议适当使用。")
|
| 319 |
+
with st.text(body="说明"):
|
| 320 |
+
st.markdown("* “联网模式”与搜索引擎一致,仅限一轮对话,不会保持之前的会话记录。")
|
| 321 |
+
with st.text(body="说明"):
|
| 322 |
+
st.markdown("* “数据模式”暂时只支持1000个单元格以内的数据分析,单元格中的内容不支持中文数据(表头也尽量使用中文)。一般运行时间在1-5分钟左右,期间需要保持网络畅通。")
|
| 323 |
+
with st.text(body="说明"):
|
| 324 |
+
st.markdown("* “数据模式”推荐上传csv格式的文件(即utf-8格式);部分Excel文件容易出现数据不兼容的情况。")
|
| 325 |
+
|
| 326 |
+
st.markdown("#### 参考资料")
|
| 327 |
+
with st.expander(label="**核心模式的专用提示词Prompt示例**", expanded=False):
|
| 328 |
+
# with st.subheader(body="提示词Prompt"):
|
| 329 |
+
st.code(body="继续用中文写一篇关于 [文章主题] 的文章,以下列句子开头:[文章开头]。", language='plaintext')
|
| 330 |
+
st.code(body="将以下文字概括为 100 个字,使其易于阅读和理解。避免使用复杂的句子结构或技术术语。", language='plaintext')
|
| 331 |
+
st.code(body="给我出一个迪奥2023春季发布会活动策划。", language='plaintext')
|
| 332 |
+
st.code(body="帮我按照正式会议结构写一个会邀:主题是xx手机游戏立项会议。", language='plaintext')
|
| 333 |
+
st.code(body="帮我写一个车内健康监测全场景落地的项目计划,用表格。", language='plaintext')
|
| 334 |
+
st.code(
|
| 335 |
+
body="同时掷两枚质地均匀的骰子,则两枚骰子向上的点数之和为 7 的概率是多少。", language='plaintext')
|
| 336 |
+
st.code(body="写一篇产品经理的演讲稿,注意使用以下词汇: 赋能,抓手,中台,闭环,落地,漏斗,沉淀,给到,同步,对齐,对标,迭代,拉通,打通,升级,交付,聚焦,倒逼,复盘,梳理,方案,联动,透传,咬合,洞察,渗透,兜底,解耦,耦合,复用,拆解。", language='plaintext')
|
| 337 |
+
|
| 338 |
+
with st.expander(label="**数据模式的专用提示词Prompt示例**", expanded=False):
|
| 339 |
+
# with st.subheader(body="提示词Prompt"):
|
| 340 |
+
st.code(body="分析此数据集并绘制一些'有趣的图表'。", language='python')
|
| 341 |
+
st.code(body="对于这个文件中的数据,你需要要找出[X,Y]数据之间的寻找'相关性'。", language='python')
|
| 342 |
+
st.code(body="对于这个文件中的[xxx]数据给我一个'整体的分析'。", language='python')
|
| 343 |
+
st.code(body="对于[xxx]数据给我一个'直方图',提供图表,并给出分析结果。", language='python')
|
| 344 |
+
st.code(body="对于[xxx]数据给我一个'小提琴图',并给出分析结果。", language='python')
|
| 345 |
+
st.code(
|
| 346 |
+
body="对于[X,Y,Z]数据在一个'分布散点图 (stripplot)',所有的数据在一张图上展现, 并给出分析结果。", language='python')
|
| 347 |
+
st.code(body="对于[X,Y]数据,进行'T检验',你需要展示图表,并给出分析结果。", language='python')
|
| 348 |
+
st.code(body="对于[X,Y]数据给我一个3个类别的'聚类分析',并给出分析结果。", language='python')
|
| 349 |
+
|
| 350 |
+
col1, col2 = st.columns(spec=[1, 2])
|
| 351 |
+
radio_2 = col2.radio(label='模式选择', options=[
|
| 352 |
+
'核心模式', '联网模式', '数据模式'], horizontal=True, label_visibility='visible')
|
| 353 |
+
# radio_1 = col1.selectbox(label='ChatGPT版本', options=[
|
| 354 |
+
# 'GPT-3.5', 'GPT-4.0'], label_visibility='visible')
|
| 355 |
+
radio_1 = col1.radio(label='ChatGPT版本', options=[
|
| 356 |
+
'GPT-3.5', 'GPT-4.0'], horizontal=True, label_visibility='visible')
|
| 357 |
+
|
| 358 |
+
# import asyncio
|
| 359 |
+
# if radio_2 != "数据模式":
|
| 360 |
+
# # * 也可以用命令执行这个python文件。’streamlit run frontend/app.py‘
|
| 361 |
+
# asyncio.run(text_mode())
|
| 362 |
+
# # upload_file()
|
| 363 |
+
# elif radio_2 == "数据模式":
|
| 364 |
+
# uploaded_file = st.file_uploader(
|
| 365 |
+
# "选择一个文件", type=(["csv", "xlsx", "xls"]))
|
| 366 |
+
# # 默认状态下没有上传文件,None,会报错。需要判断。
|
| 367 |
+
# if uploaded_file is not None:
|
| 368 |
+
# uploaded_file_path = upload_file(uploaded_file)
|
| 369 |
+
# asyncio.run(data_mode())
|
| 370 |
+
|
| 371 |
+
elif authentication_status == False:
|
| 372 |
+
st.error('⛔ 用户名或密码错误!')
|
| 373 |
+
elif authentication_status == None:
|
| 374 |
+
st.warning(' ⬅️ 请先登录!')
|
| 375 |
+
|
| 376 |
|
| 377 |
if __name__ == "__main__":
|
| 378 |
import asyncio
|
| 379 |
+
try:
|
| 380 |
+
if radio_2 != "数据模式":
|
| 381 |
+
# * 也可以用命令执行这个python文件。’streamlit run frontend/app.py‘
|
| 382 |
+
asyncio.run(text_mode())
|
| 383 |
+
# upload_file()
|
| 384 |
+
elif radio_2 == "数据模式":
|
| 385 |
+
uploaded_file = st.file_uploader(
|
| 386 |
+
"选择一个文件", type=(["csv", "xlsx", "xls"]))
|
| 387 |
+
# 默认状态下没有上传文件,None,会报错。需要判断。
|
| 388 |
+
if uploaded_file is not None:
|
| 389 |
+
uploaded_file_path = upload_file(uploaded_file)
|
| 390 |
+
asyncio.run(data_mode())
|
| 391 |
+
except:
|
| 392 |
+
# st.markdown('**请先登录!**')
|
| 393 |
+
pass
|
config.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
credentials:
|
| 2 |
+
usernames:
|
| 3 |
+
joeshi:
|
| 4 |
+
email: yunshi902@msn.com
|
| 5 |
+
name: joeshi
|
| 6 |
+
password: '$2b$12$8Jbjy0Cvq4UnXksw2PUa8.BOmssCExwIS/SrSZX4JwGWu1zJJ5Jxu' # To be replaced with hashed password
|
| 7 |
+
cindyji:
|
| 8 |
+
email: joe.joeshi@gmail.com
|
| 9 |
+
name: cindyji
|
| 10 |
+
password: '$2b$12$CA3Kc0sL0jVax7Wx0bbC7Op3edhtxlFUJkHS6ABjZCBN/1kbS3yem' # To be replaced with hashed password
|
| 11 |
+
test:
|
| 12 |
+
email: joe.joeshi@gmail.com
|
| 13 |
+
name: test
|
| 14 |
+
password: '$2b$12$ZkS1cFhMN7L7em0QOwZ8zewAwvJrt1eA5/2bpikHEyXXFpXApVBwy' # To be replaced with hashed password, test
|
| 15 |
+
|
| 16 |
+
cookie:
|
| 17 |
+
expiry_days: 30
|
| 18 |
+
key: random_signature_key # Must be string
|
| 19 |
+
name: random_cookie_name
|
| 20 |
+
preauthorized:
|
| 21 |
+
emails:
|
| 22 |
+
- joe.joeshi@gmail.com
|