Upload 2 files
Browse files- app.py +27 -30
- config.yaml +0 -1
app.py
CHANGED
@@ -36,7 +36,7 @@ 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"
|
@@ -47,6 +47,16 @@ openai.api_key = os.environ['user_token']
|
|
47 |
st.title("专业版大语言模型商业智能中心")
|
48 |
st.subheader("Artificial Intelligence Backend Center for Professionals")
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
# with tab2:
|
51 |
def upload_file(uploaded_file):
|
52 |
if uploaded_file is not None:
|
@@ -68,17 +78,19 @@ def upload_file(uploaded_file):
|
|
68 |
temp_dir = tempfile.TemporaryDirectory()
|
69 |
# ! working.
|
70 |
uploaded_file_path = pathlib.Path(temp_dir.name) / uploaded_file_name
|
71 |
-
with open('./upload.csv', 'wb') as output_temporary_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 |
-
|
77 |
|
78 |
return None
|
79 |
|
80 |
|
81 |
-
bing_search_api_key = os.environ['
|
82 |
bing_search_endpoint = 'https://api.bing.microsoft.com/v7.0/search'
|
83 |
|
84 |
def search(query):
|
@@ -192,7 +204,8 @@ async def text_mode():
|
|
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])
|
@@ -225,11 +238,7 @@ async def data_mode():
|
|
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 |
|
@@ -309,13 +318,13 @@ if authentication_status:
|
|
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("*
|
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="说明"):
|
@@ -347,26 +356,13 @@ if authentication_status:
|
|
347 |
st.code(body="对于[X,Y]数据,进行'T检验',你需要展示图表,并给出分析结果。", language='python')
|
348 |
st.code(body="对于[X,Y]数据给我一个3个类别的'聚类分析',并给出分析结果。", language='python')
|
349 |
|
350 |
-
col1, col2
|
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('⛔ 用户名或密码错误!')
|
@@ -390,4 +386,5 @@ if __name__ == "__main__":
|
|
390 |
asyncio.run(data_mode())
|
391 |
except:
|
392 |
# st.markdown('**请先登录!**')
|
393 |
-
pass
|
|
|
|
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"
|
|
|
47 |
st.title("专业版大语言模型商业智能中心")
|
48 |
st.subheader("Artificial Intelligence Backend Center for Professionals")
|
49 |
|
50 |
+
### clear conversion.
|
51 |
+
reset_button_key = "reset_button"
|
52 |
+
reset_button = st.button(label=("扫清世间烦恼,清除所有记录,并开启一轮新对话 ▶"), key=reset_button_key, use_container_width=True,type="secondary")
|
53 |
+
if reset_button:
|
54 |
+
st.session_state.conversation = None
|
55 |
+
st.session_state.chat_history = None
|
56 |
+
st.session_state.messages = []
|
57 |
+
message_placeholder = st.empty()
|
58 |
+
|
59 |
+
|
60 |
# with tab2:
|
61 |
def upload_file(uploaded_file):
|
62 |
if uploaded_file is not None:
|
|
|
78 |
temp_dir = tempfile.TemporaryDirectory()
|
79 |
# ! working.
|
80 |
uploaded_file_path = pathlib.Path(temp_dir.name) / uploaded_file_name
|
81 |
+
# with open('./upload.csv', 'wb') as output_temporary_file:
|
82 |
+
with open(f'./{name}_{time.time}_upload.csv', 'wb') as output_temporary_file:
|
83 |
+
print(f'./{name}_{time.time}_upload.csv')
|
84 |
# ! 必须用这种格式读入内容,然后才可以写入temporary文件夹中。
|
85 |
# output_temporary_file.write(uploaded_file.getvalue())
|
86 |
output_temporary_file.write(uploaded_file.getvalue())
|
87 |
# st.write(uploaded_file_path) # * 可以查看文件是否真实存在,然后是否可以
|
88 |
+
st.write('Now file saved successfully.')
|
89 |
|
90 |
return None
|
91 |
|
92 |
|
93 |
+
bing_search_api_key = os.environ['bing_api_key']
|
94 |
bing_search_endpoint = 'https://api.bing.microsoft.com/v7.0/search'
|
95 |
|
96 |
def search(query):
|
|
|
204 |
|
205 |
async def data_mode():
|
206 |
print('数据分析模式启动!')
|
207 |
+
# uploaded_file_path = './upload.csv'
|
208 |
+
uploaded_file_path = f'./{name}_{time.time}_upload.csv'
|
209 |
# # st.write(f"passed file path in data_mode: {uploaded_file_path}")
|
210 |
# tmp1 = pd.read_csv('./upload.csv')
|
211 |
# st.write(tmp1[:5])
|
|
|
238 |
-------------------------------------------------------------------------
|
239 |
1. 你需要用提问的语言来回答(如:中文提问你就用中文来回答,英文提问你就用英文来回答)。
|
240 |
2. 如果要求你输出图表,那么图的解析度dpi需要设定为300。图尽量使用seaborn库。seaborn库的参数设定:sns.set(rc={'axes.facecolor':'#FFF9ED','figure.facecolor':'#FFF9ED'}, palette='dark'。
|
241 |
+
3. 图上所有的文字全部翻译成<英文English>来表示。
|
|
|
|
|
|
|
|
|
242 |
-------------------------------------------------------------------------
|
243 |
""" # seaborn中的palette参数可以设定图表的颜色,选项包括:deep, muted, pastel, bright, dark, colorblind,Spectral。更多参数可以参考:https://seaborn.pydata.org/generated/seaborn.color_palette.html。
|
244 |
|
|
|
318 |
# st.markdown("# 欢迎使用大语言模型商业智能中心")
|
319 |
# with st.expander(label=("**重要的使用注意事项**"), expanded=True):
|
320 |
with st.container():
|
321 |
+
st.markdown("#### 快速上手指南")
|
322 |
+
# with st.text(body="说明"):
|
323 |
+
# st.markdown("* 重启一轮新对话时,只需要刷新页面(按Ctrl/Command + R)即可。")
|
324 |
with st.text(body="说明"):
|
325 |
+
st.markdown("* 为了保护数据与隐私,所有对话均不会被保存,刷新页面立即删除。敬请放心。")
|
326 |
with st.text(body="说明"):
|
327 |
+
st.markdown("* “GPT-4”回答质量极佳,但速度缓慢、且不支持长文。建议适当使用。")
|
|
|
|
|
328 |
with st.text(body="说明"):
|
329 |
st.markdown("* “联网模式”与搜索引擎一致,仅限一轮对话,不会保持之前的会话记录。")
|
330 |
with st.text(body="说明"):
|
|
|
356 |
st.code(body="对于[X,Y]数据,进行'T检验',你需要展示图表,并给出分析结果。", language='python')
|
357 |
st.code(body="对于[X,Y]数据给我一个3个类别的'聚类分析',并给出分析结果。", language='python')
|
358 |
|
359 |
+
col1, col2= st.columns(spec=[1, 2])
|
360 |
radio_2 = col2.radio(label='模式选择', options=[
|
361 |
'核心模式', '联网模式', '数据模式'], horizontal=True, label_visibility='visible')
|
362 |
# radio_1 = col1.selectbox(label='ChatGPT版本', options=[
|
363 |
# 'GPT-3.5', 'GPT-4.0'], label_visibility='visible')
|
364 |
radio_1 = col1.radio(label='ChatGPT版本', options=[
|
365 |
'GPT-3.5', 'GPT-4.0'], horizontal=True, label_visibility='visible')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
|
367 |
elif authentication_status == False:
|
368 |
st.error('⛔ 用户名或密码错误!')
|
|
|
386 |
asyncio.run(data_mode())
|
387 |
except:
|
388 |
# st.markdown('**请先登录!**')
|
389 |
+
pass
|
390 |
+
|
config.yaml
CHANGED
@@ -12,7 +12,6 @@ credentials:
|
|
12 |
email: [email protected]
|
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
|
|
|
12 |
email: [email protected]
|
13 |
name: test
|
14 |
password: '$2b$12$ZkS1cFhMN7L7em0QOwZ8zewAwvJrt1eA5/2bpikHEyXXFpXApVBwy' # To be replaced with hashed password, test
|
|
|
15 |
cookie:
|
16 |
expiry_days: 30
|
17 |
key: random_signature_key # Must be string
|