GitMarco27 commited on
Commit
747a11a
·
1 Parent(s): b1ef552

First release of frontend files compatibility

Browse files
codeinterpreterapi/schema/file.py CHANGED
@@ -6,6 +6,10 @@ class File(BaseModel):
6
  name: str
7
  content: bytes
8
 
 
 
 
 
9
  @classmethod
10
  def from_path(cls, path: str):
11
  with open(path, "rb") as f:
 
6
  name: str
7
  content: bytes
8
 
9
+ @classmethod
10
+ def from_bytes(cls, name: str, content: bytes):
11
+ return cls(name=name, content=content)
12
+
13
  @classmethod
14
  def from_path(cls, path: str):
15
  with open(path, "rb") as f:
frontend/demo.py CHANGED
@@ -2,6 +2,7 @@ import asyncio
2
 
3
  import streamlit as st
4
 
 
5
  from frontend.utils import get_images
6
 
7
  st.title('Code Interpreter API 🚀')
@@ -13,10 +14,18 @@ st.sidebar.markdown("[Github Repo](https://github.com/shroominic/codeinterpreter
13
 
14
  # This will create a textbox where you can input text
15
  input_text = st.text_input("Write your prompt")
 
 
 
 
 
 
 
 
16
 
17
  # This will create a button
18
  button_pressed = st.button('Run code interpreter', use_container_width=True)
19
 
20
  # This will display the image only when the button is pressed
21
  if button_pressed and input_text != "":
22
- asyncio.run(get_images(input_text))
 
2
 
3
  import streamlit as st
4
 
5
+ from codeinterpreterapi import File
6
  from frontend.utils import get_images
7
 
8
  st.title('Code Interpreter API 🚀')
 
14
 
15
  # This will create a textbox where you can input text
16
  input_text = st.text_input("Write your prompt")
17
+ uploaded_files = st.file_uploader("Choose a CSV file", accept_multiple_files=True,
18
+ type=".csv")
19
+
20
+ uploaded_files_list = []
21
+ for uploaded_file in uploaded_files:
22
+ bytes_data = uploaded_file.read()
23
+ uploaded_files_list.append(File.from_bytes(name=uploaded_file.name,
24
+ content=bytes_data))
25
 
26
  # This will create a button
27
  button_pressed = st.button('Run code interpreter', use_container_width=True)
28
 
29
  # This will display the image only when the button is pressed
30
  if button_pressed and input_text != "":
31
+ asyncio.run(get_images(input_text, files=uploaded_files_list))
frontend/utils.py CHANGED
@@ -2,13 +2,16 @@ from codeinterpreterapi import CodeInterpreterSession
2
  import streamlit as st
3
 
4
 
5
- async def get_images(prompt: str):
 
 
6
  with st.chat_message("user"):
7
  st.write(prompt)
8
  with st.spinner():
9
  async with CodeInterpreterSession(model='gpt-3.5-turbo') as session:
10
  response = await session.generate_response(
11
- prompt
 
12
  )
13
 
14
  with st.chat_message("assistant"):
 
2
  import streamlit as st
3
 
4
 
5
+ async def get_images(prompt: str, files: list = None):
6
+ if files is None:
7
+ files = []
8
  with st.chat_message("user"):
9
  st.write(prompt)
10
  with st.spinner():
11
  async with CodeInterpreterSession(model='gpt-3.5-turbo') as session:
12
  response = await session.generate_response(
13
+ prompt,
14
+ files=files
15
  )
16
 
17
  with st.chat_message("assistant"):