1
1
from codeinterpreterapi import CodeInterpreterSession
2
2
import streamlit as st
3
+ import tempfile
4
+ import os
5
+ import shutil
6
+
7
+
8
+ def create_temp_folder () -> str :
9
+ """
10
+ Creates a temp folder
11
+ """
12
+ temp_folder = tempfile .mkdtemp ()
13
+ return temp_folder
3
14
4
15
5
16
async def get_images (prompt : str , files : list = None ):
@@ -17,5 +28,24 @@ async def get_images(prompt: str, files: list = None):
17
28
with st .chat_message ("assistant" ):
18
29
st .write (response .content )
19
30
20
- for file in response .files :
21
- st .image (file .get_image (), caption = prompt , use_column_width = True )
31
+ # Showing Results
32
+ for _file in response .files :
33
+ st .image (_file .get_image (), caption = prompt , use_column_width = True )
34
+
35
+ # Allowing the download of the results
36
+ if len (response .files ) == 1 :
37
+ st .download_button ('Download Results' , response .files [0 ].content ,
38
+ file_name = response .files [0 ].name ,
39
+ use_container_width = True )
40
+ else :
41
+ target_path = tempfile .mkdtemp ()
42
+ for _file in response .files :
43
+ _file .save (os .path .join (target_path , _file .name ))
44
+
45
+ zip_path = os .path .join (os .path .dirname (target_path ), "archive" )
46
+ shutil .make_archive (zip_path , 'zip' , target_path )
47
+
48
+ with open (zip_path + ".zip" , 'rb' ) as f :
49
+ st .download_button ('Download Results' , f ,
50
+ file_name = "archive.zip" ,
51
+ use_container_width = True )
0 commit comments