allinaigc commited on
Commit
b02fbd4
·
1 Parent(s): a0054c1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -96
app.py CHANGED
@@ -8,10 +8,13 @@
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:solve the data analysi model issue.
15
 
16
  import requests
17
  from codeinterpreterapi import CodeInterpreterSession, File
@@ -78,25 +81,8 @@ def upload_file(uploaded_file):
78
  # ! 必须用这种格式读入内容,然后才可以写入temporary文件夹中。
79
  # output_temporary_file.write(uploaded_file.getvalue())
80
  output_temporary_file.write(uploaded_file.getvalue())
81
- # st.write(uploaded_file_path) # * 可以查看文件是否真实存在,然后是否可以
82
-
83
- # output_temporary_file.close()
84
- # new_file = tempfile.NamedTemporaryFile(delete=False)
85
- # new_file.write(uploaded_file.getvalue())
86
-
87
- # os.write(output_temporary_file, uploaded_file.getvalue())
88
- # temp_file = tempfile.NamedTemporaryFile(dir=str(uploaded_file_path), delete=False)
89
-
90
 
91
- st.write('Now file saved successfully.')
92
- # sleep(1000)
93
- # fd = os.open(uploaded_file_path, os.O_WRONLY)
94
- # os.write(fd, uploaded_file.getvalue())
95
- # os.close(fd)
96
-
97
- # return uploaded_file_path
98
- # return new_file
99
- # return new_file
100
 
101
 
102
  bing_search_api_key = os.environ['bing_api_key']
@@ -161,68 +147,6 @@ async def text_mode():
161
  message_placeholder = st.empty()
162
  full_response = ""
163
 
164
- # if radio_2 == '数据分析模式':
165
- # print('数据分析模式启动!')
166
- # with st.chat_message("assistant"):
167
- # # message_placeholder = st.empty()
168
- # # full_response = ""
169
- # async with CodeInterpreterSession() as session:
170
- # # user_request = "对于文件中的'SepalLengthCm’数据给我一个'直方图',提供图表,并给出分析结果"
171
- # #! 可以用设定dpi=300来输出高质量的图表。(注:图的解析度dpi设定为300)
172
- # environ_settings = """【背景要求】如果我没有告诉你任何定制化的要求,那么请你按照以下的默认要求来回答:
173
- # -------------------------------------------------------------------------
174
- # 1. 你需要用提问的语言来回答(如:中文提问你就用中文来回答,英文提问你就用英文来回答)。
175
- # 2. 如果要求你输出图表,那么图的解析度dpi需要设定为300。图尽量使用seaborn库。seaborn库的参数设定:sns.set(rc={'axes.facecolor':'#FFF9ED','figure.facecolor':'#FFF9ED'}, palette='dark'。
176
- # 3. 如果需要显示中文,那么设置如下:
177
- # 3.1 首先,你需要安装中文字体:
178
- # myfont=FontProperties(fname='/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/code_interpreter/rawdata/SimHei.ttf')
179
- # 3.2 然后,你需要设定在matplotlib(plt)和seaborn(sns)中设定:
180
- # sns.set_style({'font.sans-serif':['Arial','SimHei']})
181
- # plt.rcParams['font.sans-serif'] = ['SimHei']
182
- # plt.rcParams['font.family']='sans-serif'
183
- # plt.title(fontsize = 18)
184
- # -------------------------------------------------------------------------
185
- # """ # seaborn中的palette参数可以设定图表的颜色,选项包括:deep, muted, pastel, bright, dark, colorblind,Spectral。更多参数可以参考:https://seaborn.pydata.org/generated/seaborn.color_palette.html。
186
-
187
- # uploaded_file_path = upload_file()
188
-
189
- # user_request = environ_settings + "\n\n" + \
190
- # "你需要完成以下任务:\n\n" + prompt + \
191
- # f"注:文件位置在{uploaded_file_path}"
192
- # print('user_request: \n', user_request)
193
-
194
- # # 加载上传的文件,主要路径在上面代码中。
195
- # files = [File.from_path(str(uploaded_file_path))]
196
-
197
- # with st.status('thinking...', expanded=True, state='running') as status:
198
- # # generate the response
199
- # response = await session.generate_response(
200
- # user_request, files=files
201
- # )
202
-
203
- # # output to the user
204
- # print("AI: ", response.content)
205
- # full_response = response.content
206
- # ### full_response = "this is full response"
207
-
208
- # # for file in response.files:
209
- # for i, file in enumerate(response.files):
210
- # # await file.asave(f"/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/code_interpreter/output{i}.png") ##working.
211
- # # st.image(file.get_image()) #! working.
212
- # # * 注意这里的设定,可以提高图片的精细程度。
213
- # st.image(file.get_image(), width=None,
214
- # output_format='PNG')
215
-
216
- # # message_placeholder.markdown(full_response + "▌") ## orignal code.
217
- # # message_placeholder.markdown(full_response) ## orignal code.
218
- # st.write(full_response)
219
- # status.update(label='complete', state='complete')
220
- # # st.session_state.messages.append(
221
- # # {"role": "assistant", "content": full_response})
222
-
223
- # await session.astop() # ! 确认需要关闭。
224
- # # st.session_state.messages.append({"role": "assistant", "content": full_response})
225
-
226
  if radio_2 == '联网模式':
227
  # print('联网模式入口,prompt:', prompt)
228
  input_message = prompt
@@ -273,13 +197,12 @@ async def text_mode():
273
  {"role": "assistant", "content": full_response})
274
 
275
 
276
- async def data_mode(uploaded_file_path):
277
- print('数据分析模式启动!')
278
  uploaded_file_path = './upload.csv'
279
- ## TODO: validate the existence of uploaded file.
280
  # st.write(f"passed file path in data_mode: {uploaded_file_path}")
281
- tmp1 = pd.read_csv('./upload.csv')
282
- st.write(tmp1[:5])
283
 
284
  # Initialize chat history
285
  if "messages" not in st.session_state:
@@ -309,14 +232,7 @@ async def data_mode(uploaded_file_path):
309
  -------------------------------------------------------------------------
310
  1. 你需要用提问的语言来回答(如:中文提问你就用中文来回答,英文提问你就用英文来回答)。
311
  2. 如果要求你输出图表,那么图的解析度dpi需要设定为300。图尽量使用seaborn库。seaborn库的参数设定:sns.set(rc={'axes.facecolor':'#FFF9ED','figure.facecolor':'#FFF9ED'}, palette='dark'。
312
- 3. 如果需要显示中文,那么设置如下:
313
- 3.1 首先,你需要安装中文字体:
314
- myfont=FontProperties(fname='/Users/yunshi/Downloads/360Data/Data Center/Working-On Task/演讲与培训/2023ChatGPT/Coding/code_interpreter/rawdata/SimHei.ttf')
315
- 3.2 然后,你需要设定在matplotlib(plt)和seaborn(sns)中设定:
316
- sns.set_style({'font.sans-serif':['Arial','SimHei']})
317
- plt.rcParams['font.sans-serif'] = ['SimHei']
318
- plt.rcParams['font.family']='sans-serif'
319
- plt.title(fontsize = 18)
320
  -------------------------------------------------------------------------
321
  """ # seaborn中的palette参数可以设定图表的颜色,选项包括:deep, muted, pastel, bright, dark, colorblind,Spectral。更多参数可以参考:https://seaborn.pydata.org/generated/seaborn.color_palette.html。
322
 
@@ -371,7 +287,7 @@ if __name__ == "__main__":
371
  ## 默认状态下没有上传文件,None,会报错。需要判断。
372
  if uploaded_file is not None:
373
  uploaded_file_path = upload_file(uploaded_file)
374
- asyncio.run(data_mode(uploaded_file_path))
375
 
376
 
377
 
 
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
+ 1. app.py:
12
+ 1. openai key, bing key.
13
+ 1. proxy
14
+ 1.
15
 
16
  '''
17
+ # TODO:1. remove the table display in the second round. 2.
18
 
19
  import requests
20
  from codeinterpreterapi import CodeInterpreterSession, 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['bing_api_key']
 
147
  message_placeholder = st.empty()
148
  full_response = ""
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  if radio_2 == '联网模式':
151
  # print('联网模式入口,prompt:', prompt)
152
  input_message = prompt
 
197
  {"role": "assistant", "content": full_response})
198
 
199
 
200
+ async def data_mode():
201
+ # print('数据分析模式启动!')
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
 
207
  # Initialize chat history
208
  if "messages" not in st.session_state:
 
232
  -------------------------------------------------------------------------
233
  1. 你需要用提问的语言来回答(如:中文提问你就用中文来回答,英文提问你就用英文来回答)。
234
  2. 如果要求你输出图表,那么图的解析度dpi需要设定为300。图尽量使用seaborn库。seaborn库的参数设定:sns.set(rc={'axes.facecolor':'#FFF9ED','figure.facecolor':'#FFF9ED'}, palette='dark'。
235
+ 3. 表上的字体全部用<英文English>来表示。
 
 
 
 
 
 
 
236
  -------------------------------------------------------------------------
237
  """ # seaborn中的palette参数可以设定图表的颜色,选项包括:deep, muted, pastel, bright, dark, colorblind,Spectral。更多参数可以参考:https://seaborn.pydata.org/generated/seaborn.color_palette.html。
238
 
 
287
  ## 默认状态下没有上传文件,None,会报错。需要判断。
288
  if uploaded_file is not None:
289
  uploaded_file_path = upload_file(uploaded_file)
290
+ asyncio.run(data_mode())
291
 
292
 
293