Spaces:
Runtime error
Runtime error
hoollyzhang
commited on
Commit
Β·
5b402ce
1
Parent(s):
db04283
feat:Add application file
Browse files- README.md +1 -1
- app.py +25 -28
- flagged/log.csv +7 -0
- frontend/utils.py +37 -50
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: π¦
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: red
|
| 6 |
sdk: streamlit
|
| 7 |
-
sdk_version: 1.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: red
|
| 6 |
sdk: streamlit
|
| 7 |
+
sdk_version: 1.24.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
app.py
CHANGED
|
@@ -1,38 +1,35 @@
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
-
|
| 3 |
-
import streamlit as st
|
| 4 |
-
|
| 5 |
from codeinterpreterapi import File
|
| 6 |
from frontend.utils import get_images
|
| 7 |
|
| 8 |
-
# Page configuration
|
| 9 |
-
st.set_page_config(layout="wide")
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# This will create a sidebar
|
| 14 |
-
st.sidebar.title("Code Interpreter API π")
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
# This will create a button
|
| 34 |
-
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(get_images(input_text, files=uploaded_files_list))
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import asyncio
|
|
|
|
|
|
|
|
|
|
| 3 |
from codeinterpreterapi import File
|
| 4 |
from frontend.utils import get_images
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def code_interpreter_app(input_text, uploaded_file=None):
|
| 8 |
+
if uploaded_file is not None:
|
| 9 |
+
bytes_data = uploaded_file.read()
|
| 10 |
+
uploaded_file_data = File(name=uploaded_file.name, content=bytes_data)
|
| 11 |
+
output = asyncio.run(get_images(
|
| 12 |
+
input_text, files=[uploaded_file_data]))
|
| 13 |
+
else:
|
| 14 |
+
# Call get_images without files
|
| 15 |
+
output = asyncio.run(get_images(input_text))
|
| 16 |
+
return output
|
| 17 |
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# This will create a textbox where you can input text
|
| 20 |
+
input_text = gr.Textbox("Write your prompt")
|
| 21 |
|
| 22 |
+
# This will create a file uploader
|
| 23 |
+
file_uploader = gr.File(label="Upload your file", optional=True)
|
| 24 |
|
| 25 |
|
| 26 |
+
# Interface for the Gradio app
|
| 27 |
+
interface = gr.Interface(
|
| 28 |
+
fn=code_interpreter_app,
|
| 29 |
+
inputs=[input_text, file_uploader],
|
| 30 |
+
outputs=gr.Textbox("Output will be shown here"), # Dummy output
|
| 31 |
+
title="Code Interpreter API π",
|
| 32 |
+
description="η»εε₯ε₯ζcall π",
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flagged/log.csv
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
prompt,file_path,output,flag,username,timestamp
|
| 2 |
+
θε΄θζθ³,,,,,2023-07-23 13:29:43.611460
|
| 3 |
+
θε΄θζθ³,,,,,2023-07-23 13:29:45.483099
|
| 4 |
+
nihao ,,,,,,Output will be shown here,,,2023-07-23 13:32:27.341759
|
| 5 |
+
,,,,,2023-07-23 13:34:12.231896
|
| 6 |
+
1+1ηη»ζ,,Output will be shown here,,,2023-07-23 13:35:04.771405
|
| 7 |
+
hahah,,Please upload a file.,,,2023-07-23 13:36:13.694983
|
frontend/utils.py
CHANGED
|
@@ -1,51 +1,38 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
-
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 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)
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
+
|
| 5 |
+
from codeinterpreterapi import File
|
| 6 |
+
from frontend.utils import get_images
|
| 7 |
+
|
| 8 |
+
# Page configuration
|
| 9 |
+
st.set_page_config(layout="wide")
|
| 10 |
+
|
| 11 |
+
st.title('Code Interpreter API π')
|
| 12 |
+
|
| 13 |
+
# This will create a sidebar
|
| 14 |
+
st.sidebar.title("Code Interpreter API π")
|
| 15 |
+
|
| 16 |
+
st.sidebar.markdown("### η»εε₯ε₯ζcall π")
|
| 17 |
+
|
| 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(
|
| 25 |
+
"Upload your files", accept_multiple_files=True)
|
| 26 |
+
|
| 27 |
+
uploaded_files_list = []
|
| 28 |
+
for uploaded_file in uploaded_files:
|
| 29 |
+
bytes_data = uploaded_file.read()
|
| 30 |
+
uploaded_files_list.append(File(name=uploaded_file.name,
|
| 31 |
+
content=bytes_data))
|
| 32 |
+
|
| 33 |
+
# This will create a button
|
| 34 |
+
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(get_images(input_text, files=uploaded_files_list))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|