Spaces:
Runtime error
Runtime error
# -* coding:UTF-8 -* | |
# !/usr/bin/env python | |
import numpy as np | |
import gradio as gr | |
import os | |
from PIL import Image | |
from codeinterpreterapi import CodeInterpreterSession | |
def codeinterpreter(openai_key,prompt, files): | |
fileList = [] | |
if files != None: | |
for idx, file in enumerate(files): | |
fileList.append(file) | |
with CodeInterpreterSession(model="gpt-3.5-turbo",openai_api_key=openai_key) as session: | |
#async with CodeInterpreterSession(model="gpt-3.5-turbo",openai_api_key="") as session: | |
response = session.generate_response_sync(prompt, fileList,True) | |
images = [] | |
for _file in response.files: | |
images.append(_file.get_image()) | |
return [response.content,images] | |
app = gr.Interface( | |
fn=codeinterpreter, | |
inputs=[ | |
inp1=gr.Textbox(label="openai_key"), | |
inp2=gr.Textbox(label="prompt",info="input the prompt"), | |
inp3=gr.Files(), | |
], | |
outputs=["text","gallery"], | |
examples=[["Plot the nvidea stock vs microsoft stock over the last 6 months.", | |
"Plot a sin wave and show it to me.", | |
"怡亚通最近半年走势", | |
"Plot the bitcoin chart of 2023 YTD"],[inp1]] | |
) | |
app.launch() |