allinaigc commited on
Commit
8811ae8
·
1 Parent(s): 5220e33

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
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"
@@ -79,13 +79,13 @@ def upload_file(uploaded_file):
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
 
@@ -205,7 +205,7 @@ async def text_mode():
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])
@@ -237,7 +237,7 @@ async def data_mode():
237
  environ_settings = """【背景要求】如果我没有告诉你任何定制化的要求,那么请你按照以下的默认要求来回答:
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。
@@ -287,7 +287,7 @@ async def data_mode():
287
  # authentication.
288
  import yaml
289
  from yaml.loader import SafeLoader
290
- with open('./config.yaml') as file:
291
  config = yaml.load(file, Loader=SafeLoader)
292
  authenticator = stauth.Authenticate(
293
  config['credentials'],
@@ -358,7 +358,7 @@ if authentication_status:
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=[
@@ -373,11 +373,15 @@ elif authentication_status == None:
373
  if __name__ == "__main__":
374
  import asyncio
375
  try:
376
- if radio_2 != "数据模式":
 
377
  # * 也可以用命令执行这个python文件。’streamlit run frontend/app.py‘
378
  asyncio.run(text_mode())
379
- # upload_file()
380
- elif radio_2 == "数据模式":
 
 
 
381
  uploaded_file = st.file_uploader(
382
  "选择一个文件", type=(["csv", "xlsx", "xls"]))
383
  # 默认状态下没有上传文件,None,会报错。需要判断。
 
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"
 
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}_upload.csv', 'wb') as output_temporary_file:
83
+ # print(f'./{name}_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
 
 
205
  async def data_mode():
206
  print('数据分析模式启动!')
207
  # uploaded_file_path = './upload.csv'
208
+ uploaded_file_path = f'./{name}_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])
 
237
  environ_settings = """【背景要求】如果我没有告诉你任何定制化的要求,那么请你按照以下的默认要求来回答:
238
  -------------------------------------------------------------------------
239
  1. 你需要用提问的语言来回答(如:中文提问你就用中文来回答,英文提问你就用英文来回答)。
240
+ 2. 如果要求你输出图表,那么图的解析度dpi需要设定为600。图尽量使用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。
 
287
  # authentication.
288
  import yaml
289
  from yaml.loader import SafeLoader
290
+ with open('/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/code_interpreter/config.yaml') as file:
291
  config = yaml.load(file, Loader=SafeLoader)
292
  authenticator = stauth.Authenticate(
293
  config['credentials'],
 
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=[
 
373
  if __name__ == "__main__":
374
  import asyncio
375
  try:
376
+ if radio_2 == "核心模式":
377
+ print(f'radio 选择了 {radio_2}')
378
  # * 也可以用命令执行这个python文件。’streamlit run frontend/app.py‘
379
  asyncio.run(text_mode())
380
+ if radio_2 == "联网模式":
381
+ print(f'radio 选择了 {radio_2}')
382
+ # * 也可以用命令执行这个python文件。’streamlit run frontend/app.py‘
383
+ asyncio.run(text_mode())
384
+ if radio_2 == "数据模式":
385
  uploaded_file = st.file_uploader(
386
  "选择一个文件", type=(["csv", "xlsx", "xls"]))
387
  # 默认状态下没有上传文件,None,会报错。需要判断。