Spaces:
Runtime error
Runtime error
hoollyzhang
commited on
Commit
Β·
b4dde71
1
Parent(s):
49a48eb
feat: OK
Browse files
app.py
CHANGED
|
@@ -1,67 +1,46 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import asyncio
|
| 3 |
-
import tempfile
|
| 4 |
-
import os
|
| 5 |
-
import shutil
|
| 6 |
-
from codeinterpreterapi import File
|
| 7 |
-
from frontend.utils import get_images
|
| 8 |
|
| 9 |
-
|
| 10 |
-
st.set_page_config(layout="wide")
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
# This will create a sidebar
|
| 15 |
-
st.sidebar.title("Code Interpreter API π")
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
input_text = st.text_area("Write your prompt")
|
| 24 |
-
uploaded_files = st.file_uploader(
|
| 25 |
-
"Upload your files", accept_multiple_files=True)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
bytes_data = uploaded_file.read()
|
| 30 |
-
uploaded_files_list.append(File(name=uploaded_file.name,
|
| 31 |
-
content=bytes_data))
|
| 32 |
|
| 33 |
-
|
| 34 |
-
button_pressed = st.button('Run code interpreter', use_container_width=True)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
# Call the get_images function using asyncio.run to handle the async behavior
|
| 39 |
-
output = asyncio.run(get_images(input_text, files=uploaded_files_list))
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
file_name=output.files[0].name,
|
| 54 |
-
use_container_width=True)
|
| 55 |
-
else:
|
| 56 |
-
target_path = tempfile.mkdtemp()
|
| 57 |
-
for _file in output.files:
|
| 58 |
-
_file.save(os.path.join(target_path, _file.name))
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
file_name="archive.zip",
|
| 67 |
-
use_container_width=True)
|
|
|
|
|
|
|
| 1 |
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
import streamlit as st
|
|
|
|
| 4 |
|
| 5 |
+
from codeinterpreterapi import File
|
| 6 |
+
from frontend.utils import get_images
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
async def main():
|
| 10 |
|
| 11 |
+
# Page configuration
|
| 12 |
+
st.set_page_config(layout="wide")
|
| 13 |
|
| 14 |
+
st.title('Code Interpreter API π')
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# This will create a sidebar
|
| 17 |
+
st.sidebar.title("Code Interpreter API π")
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
st.sidebar.markdown("### η»εε₯ε₯ζcall π")
|
|
|
|
| 20 |
|
| 21 |
+
st.sidebar.markdown(
|
| 22 |
+
"")
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# This will create a textbox where you can input text
|
| 25 |
+
input_text = st.text_area("Write your prompt")
|
| 26 |
+
uploaded_files = st.file_uploader(
|
| 27 |
+
"Upload your files", accept_multiple_files=True)
|
| 28 |
|
| 29 |
+
uploaded_files_list = []
|
| 30 |
+
for uploaded_file in uploaded_files:
|
| 31 |
+
bytes_data = uploaded_file.read()
|
| 32 |
+
uploaded_files_list.append(File(name=uploaded_file.name,
|
| 33 |
+
content=bytes_data))
|
| 34 |
|
| 35 |
+
# This will create a button
|
| 36 |
+
button_pressed = st.button(
|
| 37 |
+
'Run code interpreter', use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
# This will display the images only when the button is pressed
|
| 40 |
+
if button_pressed and input_text != "":
|
| 41 |
+
# asyncio.run(get_images(input_text, files=uploaded_files_list))
|
| 42 |
+
loop = asyncio.get_event_loop()
|
| 43 |
+
await loop.create_task(get_images(input_text, files=uploaded_files_list))
|
| 44 |
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
asyncio.run(main())
|
|
|
|
|
|