A hackathon-built MVP for running virtual physics experiments and generating AI explanations of the results. Pick an experiment, run it, and get a plain-language breakdown of what happened and why — powered by OpenAI, with a built-in fallback so the demo never breaks if the API key is missing.
- Three interactive simulations: Ohm's Law, Projectile Motion, and Hooke's Law
- Flask REST API with a dedicated endpoint per simulation
- AI-generated explanations of results via OpenAI, with adjustable difficulty level
- Graceful degradation: works fully offline with a fallback explanation if no API key is set
- Lightweight vanilla JS frontend with charts and loading states — no framework overhead
- Backend: Flask 3, Flask-CORS, Gunicorn
- AI: OpenAI API (optional)
- Frontend: HTML/CSS/vanilla JavaScript
| Endpoint | Method | Body | Description |
|---|---|---|---|
/simulate/ohms |
POST | { "voltage": number, "resistance": number } |
Runs Ohm's Law simulation |
/simulate/projectile |
POST | { "angle": number, "velocity": number } |
Runs projectile motion simulation |
/simulate/hooke |
POST | { "force": number, "spring_constant": number } |
Runs Hooke's Law simulation (spring constant defaults to 10) |
/explain |
POST | simulation result payload | Returns an AI-generated explanation at the requested difficulty level |
backend/
├── app.py # Flask app entry point
├── routes/
│ ├── simulations.py # Simulation endpoints
│ └── explain.py # AI explanation endpoint
└── services/
├── simulations.py # Physics calculations
└── ai_explainer.py # OpenAI integration + fallback logic
frontend/
├── index.html
├── app.js
└── styles.css
-
Create and activate a Python virtual environment.
-
Install dependencies:
pip install -r backend/requirements.txt
-
(Optional) Set your OpenAI API key for live AI explanations:
export OPENAI_API_KEY=your_key_here -
Start the Flask app:
python -m backend.app
-
Open
http://127.0.0.1:5000
If OPENAI_API_KEY isn't set, the app still works end-to-end and returns a built-in fallback explanation, so the demo never breaks.