Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

AI Lab Simulator

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.

Features

  • 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

Tech Stack

  • Backend: Flask 3, Flask-CORS, Gunicorn
  • AI: OpenAI API (optional)
  • Frontend: HTML/CSS/vanilla JavaScript

API Reference

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

Project Structure

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

Run Locally

  1. Create and activate a Python virtual environment.

  2. Install dependencies:

    pip install -r backend/requirements.txt
  3. (Optional) Set your OpenAI API key for live AI explanations:

    export OPENAI_API_KEY=your_key_here
  4. Start the Flask app:

    python -m backend.app
  5. 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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages