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.
- 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.
To run this application, you need the following:
- Python 3.7+
- Required libraries:
openai
streamlit
git clone https://github.com/your-username/python-compiler.git
cd python-compiler
Install the required Python packages using pip:
pip install openai streamlit
- Create an OpenAI API key from the OpenAI API Dashboard.
- Save the API key in a text file named
.openai_api_key.txt
under thekeys
directory:mkdir keys echo "your-openai-api-key" > keys/.openai_api_key.txt
Start the Streamlit application:
streamlit run app.py
.
├── 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)
- The application reads the OpenAI API key from the
.openai_api_key.txt
file. - Users enter a Python code snippet into the text area provided by Streamlit.
- 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.
- The model generates the expected terminal output for the code, which is displayed in the Streamlit interface.
print("Hello, World!")
Hello, World!
Feel free to submit issues or pull requests to improve this project.
This project is licensed under the MIT License. See the LICENSE file for more details.