A minimal Flutter web frontend for a GPT-2 FastAPI backend.
The frontend communicates with the backend endpoint at http://localhost:8000/generate.
- Flutter SDK installed (with web and/or desktop support enabled) and on your
PATH - Python 3.10+ with virtual environment support
- Backend running (
main.pyat repository root)
From the repository root:
- Create a virtual environment and install requirements:
python -m venv venv
.\venv\Scripts\Activate.ps1
pip install -r requirements.txt- Start the backend server:
uvicorn main:app --reloadFrom the frontend folder:
flutter pub get
flutter run -d chromeNotes:
- The backend must be reachable at
http://localhost:8000. If using a different host/port, update the API URL inlib/main.dart. - If you encounter CORS issues, enable CORS in the FastAPI backend by installing
fastapi[all]orfastapi+starletteand addingCORSMiddlewareinmain.py.
You can build this Flutter app as a native Windows desktop application, so it runs without a browser.
- Windows 10/11
- Flutter SDK with Windows desktop support (
flutter doctor) - Visual Studio with Desktop development with C++ workload
- Python 3.10+ for running the backend during development
cd frontend
flutter build windows --releaseThe release executable will be created under:
build\windows\runner\Release
A helper PowerShell script (frontend/scripts/start_backend_and_app.ps1) can:
- Start the backend (via
backend.exeif available, orpython -m uvicorn main:app) - Wait until
http://127.0.0.1:8000/is available - Launch the built frontend executable
Usage example (from frontend/scripts):
.\start_backend_and_app.ps1 -BackendScript "..\..\main.py" -AppReleaseFolder "..\build\windows\runner\Release"- Option A (development): Use the launcher script with your dev Python/venv.
- Option B (single EXE): Use PyInstaller to create
backend.exe.⚠️ Note: PyTorch + Transformers result in very large executables and may require custom hooks. - Option C (portable folder): Ship a portable Python runtime or venv alongside the backend files. ✅ Often the simplest approach for ML-heavy backends.
- Zip the release folder along with the backend (EXE or venv), or
- Use installer builders (e.g. Inno Setup) to create a proper installer.
- Torch/Transformers packaging: Backends with PyTorch are large. Prefer portable Python + venv or host the model remotely instead of single-file EXEs.
- CORS issues: Desktop builds default to
http://127.0.0.1:8000. Ensure the backend allows this origin or update the base URL in app settings.
This project is licensed under the MIT License.