Spaces:
Running
Running
Update app.py
Browse filesGot code_interpreter file output downloads working
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(' ', ' ').replace(' ', ' ').replace(' ', ' ').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 |
-
|
|
|
|
| 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 |
-
|
| 917 |
-
|
| 918 |
-
|
| 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[
|
| 930 |
do_file_download = True
|
| 931 |
if do_file_download:
|
| 932 |
ext = file_name.split('.')[-1]
|
| 933 |
fpath = dataDir + user_window + '.' + ext
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
|
|
|
|
|
|
|
|
|
| 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(' ', ' ').replace(' ', ' ').replace(' ', ' ').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())
|