File size: 1,949 Bytes
c5e39b8
 
 
 
 
 
 
 
 
 
 
 
7d6868c
c5e39b8
40658fc
842c0e1
 
 
40658fc
b2c5a10
6a3a961
5de881e
bcabe95
11f72a1
8f9d8b0
c5e39b8
4cd35b4
 
 
 
 
f905e84
c5e39b8
 
9c2a562
 
 
 
 
 
 
 
 
da72220
9c2a562
 
 
c5f8aac
9c2a562
 
 
 
 
 
 
 
 
 
 
 
c5e39b8
1
2
3
4
5
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -* 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)

    if openai_key == "":
        return ['openai key must set!',None]

    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]
        

with gr.Blocks() as app:
    with gr.Row():
        with gr.Column():
            inp1=gr.Textbox(label="openai_key")
            inp2=gr.Textbox(label="prompt",info="input the prompt")
            inp3=gr.Files()
        with gr.Column():
            out1=gr.Textbox(label="result")
            out2=gr.Gallery()
        btn = gr.Button(value="Mirror Image")
    gr.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"]],
                [inp2])
    btn.click(codeinterpreter, inputs=[inp1,inp2,inp3], outputs=[out1,out2])

# app = gr.Interface(
#     fn=codeinterpreter, 
#     inputs=[inp1,inp2,inp3], 
#     outputs=["text","gallery"],
#     examples=[["","Plot the nvidea stock vs microsoft stock over the last 6 months.",None],
#                ["","Plot a sin wave and show it to me.",None],
#                ["","怡亚通最近半年走势",None],
#                ["","Plot the bitcoin chart of 2023 YTD",None]]
# )
app.launch()