1

Recently, OpenAI releasedĀ Code Interpreter in ChatGPTĀ for all paying users. However, it costs $20 per month, which is not affordable for everyone. So if you want to use ChatGPT Code Interpreter for free, this tutorial is for you. A developer who goes by the name ofĀ Shroominic has developed an open-source implementation of ChatGPTā€™s Code Interpreter. It allows you to perform dataset analysis and visualize data similar to ChatGPT. On that note, letā€™s go ahead and learn how to use Code Interpreter for free. How to Use ChatGPT Code Interpreter for Free Account

Things to Keep in Mind Before You Proceed Further

1. We are using the free and open-sourceĀ Code Interpreter API projectĀ on GitHub (visit). It uses CodeBoxes, OpenAIā€™s API, LangChain Agents, and multiple Python packages to behave like ChatGPTā€™s Code Interpreter.

2. For aĀ small dataset, it works pretty well and without any charge. However, when you throw a large dataset for analysis, OpenAIā€™s rate limit for free users prevents the operation. So if you plan to use it for large amounts of data, consider adding a payment method to your OpenAI account.

3. If you have access to the GPT-4 API, the project works well. However, I have customized the code to make it compatible with the GPT-3.5-turbo model as well.

Step 1: Set Up Code Interpreter API

1. First, you need toĀ install Python and PipĀ on your computer, for which you can follow our linked tutorial. Make sure to add python.exe to PATH during installation.

 

How to Use ChatGPT Code Interpreter for Free Account

 

2. Once you have installed Python along with Pip, open the Terminal and run the below commands to check if they areĀ set up properly. The commands should return output with their version numbers.

 

python --version
pip --version

How to Use ChatGPT Code Interpreter for Free Account

 

3. Now, run the below command toĀ install the Code Interpreter API.

 

pip install “codeinterpreterapi[all]”

How to Use ChatGPT Code Interpreter for Free Account

4. After that, go ahead andĀ get an API keyĀ from OpenAIā€™sĀ website. Click on ā€œCreate new secret keyā€ and copy the key.

How to Use ChatGPT Code Interpreter for Free Account

Step 2: Run ChatGPT Code Interpreter for Free

1. Once you do that, itā€™s time to run the Code Interpreter API for free.

2. Open aĀ code editor like Sublime TextĀ orĀ Notepad++Ā (Download).

 

How to Use ChatGPT Code Interpreter for Free Account

3. Now, copy the below code andĀ paste itĀ into the code editor. The code is from theĀ GitHubĀ page of the Code Interpreter API, but I have made some changes to avoid some errors.

 

import os os.environ[“OPENAI_API_KEY”] = “PASTE THE OPENAI API KEY HERE” from codeinterpreterapi import CodeInterpreterSession async def main(): # create a session session = CodeInterpreterSession(model=”gpt-3.5-turbo“) await session.astart() # generate a response based on user input response = await session.generate_response( “Plot the Apple stock price chart from 2007 to 2023 june” ) # output the response (text + image) print(“AI: “, response.content) for file in response.files: file.show_image() # terminate the session await session.astop() if __name__ == “__main__”: import asyncio # run the async function asyncio.run(main())

4. I have highlighted the code in red where some changes are needed. First,Ā paste the OpenAI API keyĀ in the second line.

5. After that, if you have access to the GPT-4 API, you can define the ā€œgpt-4ā€ model in the ninth line. Finally, in the 14th line, you can enter your query and define what you want to create.

 

How to Use ChatGPT Code Interpreter for Free Account

6. Now, save the file as ā€œchart.pyā€ to theĀ Desktop. Make sure to addĀ .pyĀ extension at the end.

 

How to Use ChatGPT Code Interpreter for Free Account

7. Now, go ahead and open Terminal and run the below commands one by one. The first command will move to the Desktop location and the second one will execute the ā€œchart.pyā€ file using Python.

 

cd Desktop
python chart.py

How to Use ChatGPT Code Interpreter for Free Account

8. Give it a few seconds and Code Interpreter API willĀ generate the chartĀ for you.

 

How to Use ChatGPT Code Interpreter for Free Account

9. It uses a number of services in the background to achieve this result, including LangChain Agents, Yahoo Finance data from the internet, Matplotlib to plot the graph, and more. You can add the below line to the code toĀ see everything happeningĀ in the background.

 

os.environ[“VERBOSE”] = “True”

  • How to Use ChatGPT Code Interpreter for Free Account

How to Use ChatGPT Code Interpreter for Free

10. Now onwards, you can simplyĀ change the queryĀ in the code and execute the ā€œchart.pyā€ file again to generate new charts.

 

How to Use ChatGPT Code Interpreter for Free Account

Step 3: Perform Data Analysis Using Code Interpreter API

1. You can also use your local data to perform data analysis for free. For that,Ā create a folder named ā€œanalysisā€Ā on the Desktop.

2. Now, move your dataset to the ā€œanalysisā€ folder. The dataset can be in CSV, XSL, or XSLX format. For example, we are going to use a ā€œglobaltemperature.csvā€ file inside the ā€œanalysisā€ folder.

 

How to Use ChatGPT Code Interpreter for Free Account

3. Next, open the code editor andĀ paste the below code.

 

import os os.environ[“OPENAI_API_KEY”] = “PASTE THE OPENAI API KEY HERE” from codeinterpreterapi import CodeInterpreterSession, File async def main():
# context manager for auto start/stop of the session async with CodeInterpreterSession(model=”gpt-3.5-turbo“) as session: # define the user request user_request = “Analyze this dataset and plot global temperature from the year 1950 to 2016. Consider the GCAG system.” files = [ File.from_path(“globaltemperature.csv“), ] # generate the response response = await session.generate_response( user_request, files=files ) # output to the user print(“AI: “, response.content) for file in response.files: file.show_image() if __name__ == “__main__”: import asyncio asyncio.run(main())

4. Here, you first need toĀ paste the OpenAI API key.

How to Use ChatGPT Code Interpreter for Free Account

5. Now, change ā€œglobaltemperature.csvā€ with your own dataset name. By the way, you can also change the model and user query depending on what you want from the data.

change the csv file name

6. Save it as ā€œdata.pyā€Ā inside the ā€œanalysisā€ folderĀ on your Desktop.

How to Use ChatGPT Code Interpreter for Free Account

7. Launch theĀ TerminalĀ and run the file in a similar fashion.

cd Desktop/analysis
python data.py

How to Use ChatGPT Code Interpreter for Free Account

8. You will nowĀ get the chart based on your local dataset. And this is how you can use the Code Interpreter API for dataset analysis without paying any fee.

 

 

How to Use ChatGPT Code Interpreter for Free Account How to Use ChatGPT Code Interpreter for Free Account Use ChatGPT Code Interpreter in hindi Use ChatGPT Code Interpreter in hindi Use ChatGPT Code Interpreter in hindi