johnhelf commited on
Commit
4cc9842
·
0 Parent(s):

Duplicate from johnhelf/codeinterpreter-api

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +14 -0
  3. app.py +53 -0
  4. requirements.txt +9 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Codeinterpreter Api
3
+ emoji: 🏃
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 3.39.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ duplicated_from: johnhelf/codeinterpreter-api
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -* coding:UTF-8 -*
2
+ # !/usr/bin/env python
3
+ import numpy as np
4
+ import gradio as gr
5
+
6
+ import os
7
+ from PIL import Image
8
+
9
+ from codeinterpreterapi import CodeInterpreterSession
10
+
11
+
12
+
13
+ def codeinterpreter(openai_key,prompt, files):
14
+
15
+ fileList = []
16
+ if files != None:
17
+ for idx, file in enumerate(files):
18
+ fileList.append(file)
19
+
20
+ if openai_key == "":
21
+ return ['openai key must set!',None]
22
+
23
+ with CodeInterpreterSession(model="gpt-3.5-turbo",openai_api_key=openai_key) as session:
24
+ #async with CodeInterpreterSession(model="gpt-3.5-turbo",openai_api_key="") as session:
25
+ response = session.generate_response_sync(prompt, fileList,True)
26
+
27
+ images = []
28
+
29
+ for _file in response.files:
30
+ images.append(_file.get_image())
31
+
32
+ return [response.content,images]
33
+
34
+
35
+ with gr.Blocks() as app:
36
+ with gr.Row():
37
+ with gr.Column():
38
+ inp1=gr.Textbox(label="openai_key")
39
+ inp2=gr.Textbox(label="prompt",info="input the prompt")
40
+ inp3=gr.Files()
41
+ btn = gr.Button(value="Submit")
42
+ with gr.Column():
43
+ out1=gr.Textbox(label="result")
44
+ out2=gr.Gallery()
45
+
46
+ gr.Examples([["Plot the nvidea stock vs microsoft stock over the last 6 months."],
47
+ ["Plot a sin wave and show it to me."],
48
+ ["贵州茅台最近半年走势"],
49
+ ["Plot the bitcoin chart of 2023 YTD"]],
50
+ [inp2])
51
+ btn.click(codeinterpreter, inputs=[inp1,inp2,inp3], outputs=[out1,out2],api_name="getresult")
52
+
53
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+
2
+ python-dotenv==1.0
3
+ openai==0.27
4
+ langchain==0.0.242
5
+ codeboxapi==0.0.18
6
+ streamlit==1.0
7
+ jupyter-kernel-gateway==2.0
8
+ pillow==9.5.0
9
+ codeinterpreterapi