Skip to content

amritha1611/Python-compiler-using-OpenAI-and-Streamlit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Python Compiler with OpenAI and Streamlit

This project provides a simple interface for simulating a Python compiler using OpenAI's GPT-3.5-Turbo model. Users can input Python code into a Streamlit application, and the app will return the console output as if the code were executed in a Python interpreter.

Features

  • Interactive Code Input: Enter Python code in a text area.
  • Simulated Execution: View the expected Python console output generated by GPT-3.5-Turbo.
  • Streamlit Interface: User-friendly interface for seamless interaction.

Requirements

To run this application, you need the following:

  • Python 3.7+
  • Required libraries:
    • openai
    • streamlit

Setup

Step 1: Clone the Repository

git clone https://github.com/your-username/python-compiler.git
cd python-compiler

Step 2: Install Dependencies

Install the required Python packages using pip:

pip install openai streamlit

Step 3: Set Up OpenAI API Key

  1. Create an OpenAI API key from the OpenAI API Dashboard.
  2. Save the API key in a text file named .openai_api_key.txt under the keys directory:
    mkdir keys
    echo "your-openai-api-key" > keys/.openai_api_key.txt

Step 4: Run the Application

Start the Streamlit application:

streamlit run app.py

File Structure

.
├── app.py                # Main Streamlit application script
├── keys/
│   └── .openai_api_key.txt  # Contains the OpenAI API key
├── README.md             # Project documentation
└── requirements.txt      # List of dependencies (optional)

How It Works

  1. The application reads the OpenAI API key from the .openai_api_key.txt file.
  2. Users enter a Python code snippet into the text area provided by Streamlit.
  3. Upon clicking the "Compile" button, the code is sent to OpenAI's GPT-3.5-Turbo model with a system prompt to act as a Python compiler.
  4. The model generates the expected terminal output for the code, which is displayed in the Streamlit interface.

Example

Input:

print("Hello, World!")

Output:

Hello, World!

Contributing

Feel free to submit issues or pull requests to improve this project.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages