Spaces:
Runtime error
Runtime error
hoollyzhang
commited on
Commit
·
95fb4b1
1
Parent(s):
07f8ef5
feat: 默认打印
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
-
import asyncio
|
| 2 |
-
|
| 3 |
import streamlit as st
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
from codeinterpreterapi import File
|
| 6 |
from frontend.utils import get_images
|
| 7 |
|
|
@@ -18,7 +19,6 @@ st.sidebar.markdown("### 给勇哥哥打call 🚀")
|
|
| 18 |
st.sidebar.markdown(
|
| 19 |
"")
|
| 20 |
|
| 21 |
-
|
| 22 |
# This will create a textbox where you can input text
|
| 23 |
input_text = st.text_area("Write your prompt")
|
| 24 |
uploaded_files = st.file_uploader(
|
|
@@ -35,4 +35,33 @@ button_pressed = st.button('Run code interpreter', use_container_width=True)
|
|
| 35 |
|
| 36 |
# This will display the images only when the button is pressed
|
| 37 |
if button_pressed and input_text != "":
|
| 38 |
-
asyncio.run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
|
|
| 19 |
st.sidebar.markdown(
|
| 20 |
"")
|
| 21 |
|
|
|
|
| 22 |
# This will create a textbox where you can input text
|
| 23 |
input_text = st.text_area("Write your prompt")
|
| 24 |
uploaded_files = st.file_uploader(
|
|
|
|
| 35 |
|
| 36 |
# This will display the images only when the button is pressed
|
| 37 |
if button_pressed and input_text != "":
|
| 38 |
+
# Call the get_images function directly without asyncio.run
|
| 39 |
+
output = get_images(input_text, files=uploaded_files_list)
|
| 40 |
+
|
| 41 |
+
# Display output and images
|
| 42 |
+
if output:
|
| 43 |
+
with st.spinner():
|
| 44 |
+
st.write(output.content)
|
| 45 |
+
|
| 46 |
+
for _file in output.files:
|
| 47 |
+
st.image(_file.get_image(), caption=input_text,
|
| 48 |
+
use_column_width=True)
|
| 49 |
+
|
| 50 |
+
# Allowing the download of the results
|
| 51 |
+
if len(output.files) == 1:
|
| 52 |
+
st.download_button('Download Results', output.files[0].content,
|
| 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 |
+
zip_path = os.path.join(
|
| 61 |
+
os.path.dirname(target_path), "archive")
|
| 62 |
+
shutil.make_archive(zip_path, 'zip', target_path)
|
| 63 |
+
|
| 64 |
+
with open(zip_path + ".zip", 'rb') as f:
|
| 65 |
+
st.download_button('Download Results', f,
|
| 66 |
+
file_name="archive.zip",
|
| 67 |
+
use_container_width=True)
|