dlflannery commited on
Commit
7ef4ab6
·
verified ·
1 Parent(s): fa87d91

Update app.py

Browse files

Got code_interpreter file output downloads working

Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -191,7 +191,7 @@ def md(txt):
191
  # if 'DOCTYPE' in txt:
192
  # return str(txt.replace('GPT','<br>GPT'))
193
  # else:
194
- return str(txt).replace('```', ' ').replace(' ', '&nbsp;&nbsp;').replace(' ', '&nbsp;&nbsp;').replace(' ', '&nbsp;&nbsp;').replace('\n','<br>')
195
  # return txt
196
 
197
  def etz_now():
@@ -768,7 +768,8 @@ code.
768
  Do not use latex for math expressions in text output.
769
  If a chart, table or plot is produced, return it as an image.
770
  If a powerpoint slide is created, return it as an image but do not offer a download link.
771
- When possible provide a file annotation in the text results for each file you generate.
 
772
  '''
773
  response = Client().responses.create(
774
  model= "gpt-5-mini", #"gpt-5-mini", "o4-mini",
@@ -913,12 +914,9 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
913
  file_list_json = json.loads(file_list_object.content)
914
  for file_item in file_list_json['data']:
915
  file_bytes = file_item['bytes']
916
- if file_bytes == None:
917
- continue
918
- else:
919
- file_id = file_item['id']
920
- file_name = file_item['path']
921
- code_files.append((cont_id, file_id, file_name))
922
  except:
923
  pass
924
  do_file_download = False
@@ -926,16 +924,19 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
926
  (cont_id, file_id, file_name) = ann_files[-1]
927
  do_file_download = True
928
  elif len(code_files) > 0:
929
- (cont_id, file_id, file_name) = code_files[-1]
930
  do_file_download = True
931
  if do_file_download:
932
  ext = file_name.split('.')[-1]
933
  fpath = dataDir + user_window + '.' + ext
934
- data = get_openai_file(file_id, cont_id).content
935
- with open(fpath,'wb') as fp:
936
- fp.write(data)
937
- file_name = os.path.basename(file_name)
938
- file_out = gr.DownloadButton(label='Download '+ file_name, visible=True, value=fpath)
 
 
 
939
  # text += '\nIf a download link is given above, ignore it. Use the button below'
940
  out_text = "\n".join(line for line in text.splitlines() if
941
  'download' not in line.casefold())
 
191
  # if 'DOCTYPE' in txt:
192
  # return str(txt.replace('GPT','<br>GPT'))
193
  # else:
194
+ return str(txt).replace('```', ' ').replace(' ', '&nbsp;&nbsp;').replace(' ', '&nbsp;&nbsp;').replace(' ', '&nbsp;&nbsp;').replace('\n','<br>').replace('~~','~')
195
  # return txt
196
 
197
  def etz_now():
 
768
  Do not use latex for math expressions in text output.
769
  If a chart, table or plot is produced, return it as an image.
770
  If a powerpoint slide is created, return it as an image but do not offer a download link.
771
+ If the user asks you to output a file, You must include the file you generate in the annotation
772
+ of the output text using a markdown url link in this format as an example: sandbox:/mnt/data/int100.txt
773
  '''
774
  response = Client().responses.create(
775
  model= "gpt-5-mini", #"gpt-5-mini", "o4-mini",
 
914
  file_list_json = json.loads(file_list_object.content)
915
  for file_item in file_list_json['data']:
916
  file_bytes = file_item['bytes']
917
+ file_id = file_item['id']
918
+ file_name = file_item['path']
919
+ code_files.append((cont_id, file_id, file_name))
 
 
 
920
  except:
921
  pass
922
  do_file_download = False
 
924
  (cont_id, file_id, file_name) = ann_files[-1]
925
  do_file_download = True
926
  elif len(code_files) > 0:
927
+ (cont_id, file_id, file_name) = code_files[0]
928
  do_file_download = True
929
  if do_file_download:
930
  ext = file_name.split('.')[-1]
931
  fpath = dataDir + user_window + '.' + ext
932
+ try:
933
+ data = get_openai_file(file_id, cont_id).content
934
+ with open(fpath,'wb') as fp:
935
+ fp.write(data)
936
+ file_name = os.path.basename(file_name)
937
+ file_out = gr.DownloadButton(label='Download '+ file_name, visible=True, value=fpath)
938
+ except:
939
+ text += f'\nUnable to load code-generated file: {file_name}'
940
  # text += '\nIf a download link is given above, ignore it. Use the button below'
941
  out_text = "\n".join(line for line in text.splitlines() if
942
  'download' not in line.casefold())