A Streamlit web application for converting pseudocode to Python code using a fine-tuned GPT-2 model.
- 🐍 Convert pseudocode to Python code using fine-tuned GPT-2 model
- ⚙️ Adjustable generation parameters (temperature, top-p, max length)
- 🎨 Clean and intuitive user interface
- 📋 One-click code copying
- 💻 GPU support (CUDA) when available
-
Install dependencies:
pip install -r requirements.txt
-
Ensure model files are in the same directory:
model.safetensors(orpytorch_model.bin)config.jsontokenizer_config.jsonvocab.jsonmerges.txtspecial_tokens_map.jsongeneration_config.json(optional)
-
Run the Streamlit app:
streamlit run app.py
The app will open in your default web browser at
http://localhost:8501
- Enter your pseudocode in the text area
- Adjust generation parameters in the sidebar (optional)
- Click "Generate Python Code" button
- Copy the generated code using the copy button
create integer variable xread input from userif x greater than 5 print yesfor i from 0 to 10 print icreate list numbers
- Base Model: GPT-2 Small
- Training Dataset: SPOC (Pseudocode to Code)
- Task: Pseudocode → Python Code Generation
- Architecture: GPT2LMHeadModel (12 layers, 768 hidden size)
- Python 3.8+
- PyTorch
- Transformers library
- Streamlit
- Upload all your files to a GitHub repository:
app.pyrequirements.txt- All model files (
model.safetensors,config.json,tokenizer_config.json,vocab.json,merges.txt,special_tokens_map.json) .streamlit/config.toml(optional, for custom theming)
- Go to share.streamlit.io
- Sign in with your GitHub account
- Click "New app"
- Select your repository and branch
- Set the main file path to:
app.py - Click "Deploy"
- Git LFS Configuration: The repository includes
.lfsconfigto ensure Git LFS uses HTTPS (not SSH) for downloads - Model Size: Model files are stored with Git LFS. Streamlit Cloud will automatically handle the download
- Memory Limits: Streamlit Cloud has memory limits, so ensure your model fits within the constraints
- Startup Time: First load may take a few minutes as Streamlit Cloud installs dependencies and loads your model
- CPU Only: Streamlit Cloud runs on CPU, so GPU optimizations won't apply
If you see "Permission denied (publickey)" errors, ensure:
- The repository is public (recommended for Streamlit Cloud)
- The
.lfsconfigfile is committed to the repository - Try rebooting the app on Streamlit Cloud
If your model is too large for GitHub, modify app.py to download from cloud storage:
# Add this to load_model() function if needed
import requests
def download_model_from_url(url, local_path):
response = requests.get(url, stream=True)
with open(local_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)If you want to test locally before deploying:
-
Install dependencies:
pip install -r requirements.txt
-
Run the app:
streamlit run app.py
- The model automatically uses GPU if CUDA is available (local only; Streamlit Cloud uses CPU)
- Generation parameters can be adjusted in the sidebar for different outputs
- The model expects pseudocode in natural language format