Text-to-SQL in the medical domain is a task which converts natural language text to its corresponding SQL syntax. This is aimed at increasing accessibility for medical personnel who is not familiar with SQL syntax, but needs to query a structured database.
This is an app built written in Dart which queries a text-to-SQL model, sqlcoder-7b. Dart allows for cross-platform (IOS and Android) compilation. The code is written with perplexity.AI, DeepSeek-V3 and ChatGPT's help 😊.
To run it, please:
git clone https://github.com/awxlong/ai_sql_coder
pip install -r sql_generator_backend/requirements.txt
- Run the backend which initializes sqlcoder-7b using the command
flask --app app run --debug --host=0.0.0.0 --port=5001
- Inside
lib/main.dart
, you can select a virtual device and run the app (flutter pub get; flutter run
), and make natural language queries. Feel free to modify the database schema insql_generator_backend/app.py
according to your needs. If you've installed the app in a virtual device or your android/IOS, then you can just run the app and input queries as shown in the demo.
- sqlcoder-7b is hosted in a backend server with flask.
- A template prompt is fed to sqlcoder-7b which specifies a database schema. The schema we're currently using is from a small table obtained from a free, open-source demo of the MIMIC-IV Clinical Database
- The app sends user input queries to the sqlcoder-7b and displays the corresponding SQL syntax.
- Some postprocessing occurs where we ensure the output SQL adheres to SQLite syntax, since sqlcoder-7b also outputs PostgreSQL.
- The query is executed on the demo database, and shows results. We handle errors such as mentioning columns which aren't in the schema by showing an answer "Not Applicable".
- Currently, inference takes very long (~40 seconds), so we need to optimize throughput. I'm looking at activation-aware quantization, which could hopefully give me both speed up, and a dramatic reduction in computational memory consumption.
- Recently, there's also work on text to FHIR as part of MIMIC-IV, so it'd be interesting to train and deploy a model in that domain.
A few resources to get you started if this is your first Flutter project:
For help getting started with Flutter development, view the online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.
This project is licensed under the MIT License. See the LICENSE file for details.